1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "VisuGUI_ClippingPanel.h"
22 #include "VisuGUI_Tools.h"
23 #include "VisuGUI_ClippingPlaneDlg.h"
24 #include "VisuGUI_ViewTools.h"
26 #include <VISU_ColoredPrs3dCache_i.hh>
28 #include <VISU_Gen_i.hh>
29 #include <VISU_ColoredPrs3dHolder_i.hh>
31 #include <LightApp_Application.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_ViewManager.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SUIT_ViewWindow.h>
38 #include <SVTK_ViewWindow.h>
39 #include <VTKViewer_Utilities.h>
43 #include <QVBoxLayout>
44 #include <QHBoxLayout>
45 #include <QPushButton>
46 #include <QToolButton>
48 #include <QListWidget>
49 #include <QTableWidget>
50 #include <QStringList>
51 #include <QMessageBox>
54 #include <vtkImageData.h>
55 #include <vtkCutter.h>
56 #include <vtkPolyDataMapper.h>
58 #include <SALOMEDSClient_AttributeSequenceOfReal.hxx>
59 #include <SALOMEDSClient_AttributeInteger.hxx>
63 #define SIZEFACTOR 1.1
66 #define PRINT3(MARK, VAL) printf("#### %s x=%f, y=%f, z=%f\n", MARK, VAL[0], VAL[1], VAL[2]);
71 void AdjustBounds(const double bounds[6], double newBounds[6], double center[3])
73 center[0] = (bounds[0] + bounds[1])/2.0;
74 center[1] = (bounds[2] + bounds[3])/2.0;
75 center[2] = (bounds[4] + bounds[5])/2.0;
77 newBounds[0] = center[0] + SIZEFACTOR*(bounds[0]-center[0]);
78 newBounds[1] = center[0] + SIZEFACTOR*(bounds[1]-center[0]);
79 newBounds[2] = center[1] + SIZEFACTOR*(bounds[2]-center[1]);
80 newBounds[3] = center[1] + SIZEFACTOR*(bounds[3]-center[1]);
81 newBounds[4] = center[2] + SIZEFACTOR*(bounds[4]-center[2]);
82 newBounds[5] = center[2] + SIZEFACTOR*(bounds[5]-center[2]);
87 //****************************************************************
88 //PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds):
89 PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow,
90 VISU_CutPlaneFunction* thePlane,
91 const double* theBounds):
98 AdjustBounds(myBounds, aBound, aCenter);
100 //myPlane = thePlane.plane;
103 myBox = vtkImageData::New();
104 myBox->SetDimensions(2, 2, 2);
105 myBox->SetOrigin(aBound[0],aBound[2],aBound[4]);
106 myBox->SetSpacing((aBound[1]-aBound[0]),
107 (aBound[3]-aBound[2]),
108 (aBound[5]-aBound[4]));
110 myCutter = vtkCutter::New();
111 myCutter->SetInput(myBox);
112 myCutter->SetCutFunction(myPlane);
114 myMapper = vtkPolyDataMapper::New();
115 myMapper->SetInput(myCutter->GetOutput());
117 myActor = vtkActor::New();
118 myActor->VisibilityOff();
119 myActor->PickableOff();
120 myActor->SetMapper(myMapper);
121 vtkProperty* aProp = vtkProperty::New();
124 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
126 QColor aFillColor = aResourceMgr->colorValue("SMESH", "fill_color", QColor(0, 170, 255));
127 anRGB[0] = aFillColor.red()/255.;
128 anRGB[1] = aFillColor.green()/255.;
129 anRGB[2] = aFillColor.blue()/255.;
130 aProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
131 aProp->SetOpacity(0.75);
132 myActor->SetBackfaceProperty(aProp);
135 vtkProperty* aBackProp = vtkProperty::New();
136 QColor aBackFaceColor = aResourceMgr->colorValue("SMESH", "backface_color", QColor(0, 0, 255));
137 anRGB[0] = aBackFaceColor.red()/255.;
138 anRGB[1] = aBackFaceColor.green()/255.;
139 anRGB[2] = aBackFaceColor.blue()/255.;
140 aBackProp->SetColor(anRGB[0],anRGB[1],anRGB[2]);
141 aBackProp->SetOpacity(0.75);
142 myActor->SetProperty(aBackProp);
145 myWindow->getRenderer()->AddActor(myActor);
148 //****************************************************************
149 PreviewPlane::~PreviewPlane()
151 myWindow->getRenderer()->RemoveActor(myActor);
154 myMapper->RemoveAllInputs();
164 //****************************************************************
165 //****************************************************************
166 //****************************************************************
167 /*CutPlaneFunction* CutPlaneFunction::New()
169 return new CutPlaneFunction();
172 void CutPlaneFunction::setActive(bool theActive)
174 myIsActive = theActive;
178 double CutPlaneFunction::EvaluateFunction(double x[3])
181 return vtkPlane::EvaluateFunction(x);
186 double CutPlaneFunction::EvaluateFunction(double x, double y, double z)
189 return vtkPlane::EvaluateFunction(x,y,z);
194 CutPlaneFunction::CutPlaneFunction():
200 CutPlaneFunction::~CutPlaneFunction()
206 //****************************************************************
207 //****************************************************************
208 //****************************************************************
209 VisuGUI_ClippingPanel::VisuGUI_ClippingPanel( VisuGUI* theModule, QWidget* theParent )
210 : VisuGUI_Panel( tr( "TITLE" ), theModule, theParent, ApplyBtn | HelpBtn ),
215 setWindowTitle( tr( "TITLE" ) );
216 setObjectName( tr( "TITLE" ) );
218 QVBoxLayout* aMainLayout = new QVBoxLayout(mainFrame());
220 // List of presentations
221 aMainLayout->addWidget(new QLabel(tr("PRESENTATIONS_LBL"), mainFrame()));
222 myPrsList = new QListWidget(mainFrame());
223 myPrsList->setSelectionMode(QAbstractItemView::SingleSelection);
224 connect(myPrsList, SIGNAL(currentRowChanged(int)), this, SLOT(onPrsSelected(int)));
225 aMainLayout->addWidget(myPrsList);
228 aMainLayout->addWidget(new QLabel(tr("PLANES_LBL"), mainFrame()));
229 myPlanesList = new QTableWidget(0, 2, mainFrame());
230 myPlanesList->setColumnWidth(1, 50);
231 myPlanesList->setSelectionMode(QAbstractItemView::SingleSelection);
232 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
233 aMainLayout->addWidget(myPlanesList);
235 // Management buttons
236 QWidget* aButtonsWgt = new QWidget(mainFrame());
237 QHBoxLayout* aBtnLayout = new QHBoxLayout(aButtonsWgt);
238 aMainLayout->addWidget(aButtonsWgt);
240 QToolButton* aNewBtn = new QToolButton(aButtonsWgt);
241 aNewBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
242 aNewBtn->setText(tr("NEW_BTN"));
243 connect(aNewBtn, SIGNAL(clicked(bool)), this, SLOT(onNew()));
244 aBtnLayout->addWidget(aNewBtn);
246 QToolButton* aEditBtn = new QToolButton(aButtonsWgt);
247 aEditBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
248 aEditBtn->setText(tr("EDIT_BTN"));
249 connect(aEditBtn, SIGNAL(clicked(bool)), this, SLOT(onEdit()));
250 aBtnLayout->addWidget(aEditBtn);
252 QToolButton* aDeleteBtn = new QToolButton(aButtonsWgt);
253 aDeleteBtn->setToolButtonStyle(Qt::ToolButtonTextOnly);
254 aDeleteBtn->setText(tr("DELETE_BTN"));
255 connect(aDeleteBtn, SIGNAL(clicked(bool)), this, SLOT(onPlaneDelete()));
256 aBtnLayout->addWidget(aDeleteBtn);
258 myShowPlanes = new QCheckBox(tr("CHK_SHOW_PLANES"), mainFrame());
259 connect(myShowPlanes, SIGNAL( toggled(bool) ), this, SLOT( setPlanesVisible(bool) ));
260 aMainLayout->addWidget(myShowPlanes);
262 myNonActivePlanes = new QCheckBox(tr("CHK_ACTIVATE_PLANES"), mainFrame());
263 connect(myNonActivePlanes, SIGNAL(toggled(bool)), this, SLOT(setPlanesNonActive(bool)));
264 aMainLayout->addWidget(myNonActivePlanes);
266 myAutoApply = new QCheckBox(tr("CHK_AUTO_APPLY"), mainFrame());
267 connect(myAutoApply, SIGNAL(toggled(bool)), myApply, SLOT(setDisabled(bool)));
268 myAutoApply->setCheckState(Qt::Checked);
269 aMainLayout->addWidget(myAutoApply);
275 connect(myModule, SIGNAL(presentationCreated(VISU::Prs3d_i*)),
276 this, SLOT(onPresentationCreate(VISU::Prs3d_i*)));
277 connect(myModule, SIGNAL(beforeObjectDelete(QString)),
278 this, SLOT(onObjectDelete(QString)));
280 SUIT_Desktop* aDesktop = VISU::GetDesktop(myModule);
281 connect(aDesktop, SIGNAL(windowActivated(SUIT_ViewWindow*)),
282 this, SLOT(onWindowActivated(SUIT_ViewWindow*)));
286 //*************************************************************************
287 VisuGUI_ClippingPanel::~VisuGUI_ClippingPanel()
292 //*************************************************************************
293 void VisuGUI_ClippingPanel::fillPrsList()
296 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
297 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
301 myPresentations = getPrsList(aStudy, aVisuSO);
303 //Process Cache system folder
304 _PTR(SObject) aSObjPtr = aStudy->FindObject(VISU::ColoredPrs3dCache_i::GetFolderName().c_str());
306 _PTR(ChildIterator) Iter = aStudy->NewChildIterator( aSObjPtr );
307 for ( ; Iter->More(); Iter->Next() ) {
308 _PTR(SObject) aChildObj = Iter->Value();
309 myPresentations.append(aChildObj->GetID().c_str());
314 for (int i = 0; i < myPresentations.size(); i++) {
315 if (VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(i)))
316 aNames.append(getPrsName(aPrs));
318 myPrsList->addItems(aNames);
321 //*************************************************************************
322 QString VisuGUI_ClippingPanel::getPrsName(VISU::Prs3d_i* thePrs)
327 SALOMEDS::SObject_var aSObject = thePrs->GetSObject();
328 if (!aSObject->_is_nil()) {
329 SALOMEDS::SObject_var aFather = aSObject->GetFather();
330 while (!aFather->_is_nil()) {
331 QString aFName = aFather->GetName();
332 aPath.append(aFName);
333 if (aFName == "Post-Pro") break;
334 aFather = aFather->GetFather();
336 aObjName = aSObject->GetName();
338 VISU::ColoredPrs3d_i* aColPrs = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs);
340 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
341 _PTR(SObject) aSObjPtr = aStudy->FindObjectID(aColPrs->GetHolderEntry().c_str());
343 _PTR(SObject) aFather = aSObjPtr->GetFather();
345 QString aFName(aFather->GetName().c_str());
346 aPath.append(aFName);
347 if (aFName == "Post-Pro") break;
348 aFather = aFather->GetFather();
351 aObjName = aSObjPtr->GetName().c_str();
354 for (int j = aPath.size() - 2; j >= 0; j--)
355 aName += aPath.at(j) + "/";
360 //*************************************************************************
361 QStringList VisuGUI_ClippingPanel::getPrsList(_PTR(Study) theStudy,
362 _PTR(SObject) theObject)
364 //QList<VISU::Prs3d_i*> aList;
366 _PTR(ChildIterator) aIter = theStudy->NewChildIterator(theObject);
367 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
368 _PTR(SObject) aSObject = aIter->Value();
369 std::vector<VISU::Prs3d_i*> aSTLList = VISU::GetPrs3dList(myModule, aSObject, true /* enable GaussPoints */);
370 for (int i = 0; i < aSTLList.size(); i++) {
371 VISU::Prs3d_i* aPrs = aSTLList[i];
372 if (!aList.contains(aPrs->GetEntry().c_str()))
373 aList.append(aPrs->GetEntry().c_str());
375 if (aList.size() == 0) {
376 //QList<VISU::Prs3d_i*> aSubList = getPrsList(theStudy, aSObject);
377 QStringList aSubList = getPrsList(theStudy, aSObject);
378 for (int i = 0; i < aSubList.size(); i++) {
379 //VISU::Prs3d_i* aPrs = aSubList[i];
380 QString aPrsEntry = aSubList[i];
381 if (!aList.contains(aPrsEntry))
382 aList.append(aPrsEntry);
389 //*************************************************************************
390 VISU_ClippingPlaneMgr& VisuGUI_ClippingPanel::getPlanesMgr() const
392 return VISU::GetVisuGen(myModule)->GetClippingPlaneMgr();
395 //*************************************************************************
396 void VisuGUI_ClippingPanel::fillPlanesList()
398 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
399 myPlanesList->clear();
400 _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
401 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
402 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
403 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i);
404 myPlanesList->insertRow(i);
405 QTableWidgetItem* aItem = new QTableWidgetItem(aPlane->getName().c_str());
406 QTableWidgetItem* aCheckItem = new QTableWidgetItem();
407 aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)?
408 Qt::Unchecked : Qt::Checked);
409 if (aPlane->isAuto()) { // If this is Auto plane
411 aItem->setCheckState(Qt::Checked);
412 } else { // if it is not auto
413 aItem->setCheckState(Qt::Unchecked);
414 // Check current presentation
415 int aPrsNum = myPrsList->currentRow();
417 if (VISU_ClippingPlaneMgr::ContainsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane))
418 aItem->setCheckState(Qt::Checked);
421 myPlanesList->setItem(i, 0, aItem);
422 myPlanesList->setItem(i, 1, aCheckItem);
424 myPlanesList->setHorizontalHeaderLabels(QString(tr("PLANES_TABLE_TITLES")).split(","));
426 myViewWindow->Repaint();
428 /*_PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule));
429 _PTR(SObject) aFolder;
430 if (VISU::getClippingPlanesFolder(aStudy, aFolder)) {
431 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aFolder);
433 for (i = 0; aIter->More(); aIter->Next(), i++) { // For each plane
434 _PTR(SObject) aSObject = aIter->Value();
435 PlaneDef aNewPlane = createEmptyPlane();
436 updatePlane(aSObject, aNewPlane);
438 myPlanesList->insertRow(i);
439 QTableWidgetItem* aItem = new QTableWidgetItem(aNewPlane.name);
440 QTableWidgetItem* aCheckItem = new QTableWidgetItem();
441 aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)? Qt::Unchecked : Qt::Checked);
443 if (aNewPlane.isAuto) { // If this is Auto plane
445 // apply to all presentations
446 aItem->setCheckState(Qt::Checked);
447 foreach(QString aPrsEntry, myPresentations) {
448 getPrs(aPrsEntry)->AddClippingPlane(aNewPlane.plane);
450 } else { // if it is not auto
451 foreach(QString aPrsEntry, myPresentations) {
452 _PTR(ChildIterator) aRefIter = aStudy->NewChildIterator(aSObject);
453 for (; aRefIter->More(); aRefIter->Next()) {
454 _PTR(SObject) aObj = aRefIter->Value();
455 _PTR(SObject) aRefPrsObject;
456 if (aObj->ReferencedObject(aRefPrsObject)) { // If it is referenced on current plane
457 if (QString(aRefPrsObject->GetID().c_str()) == aPrsEntry) {
458 getPrs(aPrsEntry)->AddClippingPlane(aNewPlane.plane);
463 aItem->setCheckState(Qt::Unchecked);
464 // Check current presentation
465 int aPrsNum = myPrsList->currentRow();
467 if (containsPlane(getPrs(myPresentations.at(aPrsNum)), aNewPlane))
468 aItem->setCheckState(Qt::Checked);
471 myPlanesList->setItem(i, 0, aItem);
472 myPlanesList->setItem(i, 1, aCheckItem);
473 myPlanes.append(aNewPlane);
476 myPlanesList->setHorizontalHeaderLabels(QString(tr("PLANES_TABLE_TITLES")).split(","));
478 myViewWindow->Repaint();*/
479 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
483 //*************************************************************************
484 void VisuGUI_ClippingPanel::init()
486 myViewWindow = VISU::GetViewWindow<SVTK_Viewer>(myModule);
488 connect(myViewWindow, SIGNAL(destroyed(QObject*)), this, SLOT(onWindowDestroyed(QObject*)));
493 void VisuGUI_ClippingPanel::onWindowDestroyed(QObject* theWnd)
495 if (theWnd == myViewWindow) {
500 //*************************************************************************
501 //void VisuGUI_ClippingPanel::showEvent(QShowEvent* event)
503 // VisuGUI_Panel::showEvent(event);
506 //*************************************************************************
507 // void VisuGUI_ClippingPanel::hideEvent(QHideEvent* event)
509 // disconnect(myModule, SIGNAL(presentationCreated()), this, SLOT(onPresentationCreate()));
510 // VisuGUI_Panel::hideEvent(event);
513 //*************************************************************************
514 void VisuGUI_ClippingPanel::onPresentationCreate(VISU::Prs3d_i* thePrs)
516 myPrsList->addItem(getPrsName(thePrs));
517 string aEntry = thePrs->GetEntry();
518 if (aEntry.length() == 0) {
519 VISU::ColoredPrs3d_i* aColPrs = dynamic_cast<VISU::ColoredPrs3d_i*>(thePrs);
521 aEntry = aColPrs->GetHolderEntry();
524 myPresentations.append(aEntry.c_str());
525 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
526 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
527 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i);
528 if (aPlane->isAuto())
529 aMgr.ApplyClippingPlane(thePrs, i);
531 /* for (int i = 0; i < myPlanes.size(); i++) {
532 const PlaneDef& aPlane = myPlanes.at(i);
534 thePrs->AddClippingPlane(aPlane.plane);
538 //*************************************************************************
539 /*PlaneDef VisuGUI_ClippingPanel::createEmptyPlane()
542 aPlane.name = QString("Plane");
543 aPlane.plane = CutPlaneFunction::New();
544 aPlane.plane->Delete();
545 aPlane.plane->SetOrigin(0.,0.,0.);
546 aPlane.plane->SetNormal(0.,0.,1.);
547 aPlane.isAuto = true;
551 //*************************************************************************
552 /*void VisuGUI_ClippingPanel::updatePlane(_PTR(SObject) theObject, PlaneDef& thePlane)
554 thePlane.name = QString(theObject->GetName().c_str());
555 thePlane.plane->setPlaneObject(theObject);
557 _PTR(GenericAttribute) anAttr;
558 if (theObject->FindAttribute(anAttr, "AttributeSequenceOfReal")) {
559 _PTR(AttributeSequenceOfReal) aArray(anAttr);
560 thePlane.plane->SetOrigin(aArray->Value(1), aArray->Value(2), aArray->Value(3));
561 thePlane.plane->SetNormal(aArray->Value(4), aArray->Value(5), aArray->Value(6));
563 if (theObject->FindAttribute(anAttr, "AttributeInteger")) {
564 _PTR(AttributeInteger) aFlag(anAttr);
565 thePlane.isAuto = (aFlag->Value() == 1);
569 //*************************************************************************
570 void VisuGUI_ClippingPanel::onNewPlane()
572 disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
573 disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
574 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
575 //_PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj();
576 int aId = myPlaneDlg->planeId();
577 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
579 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aId);
580 //PlaneDef aNewPlane = createEmptyPlane();
581 //updatePlane(aPlaneSObj, aNewPlane);
582 int aRow = myPlanesList->rowCount();
583 myPlanesList->insertRow(aRow);
585 //QTableWidgetItem* aItem = new QTableWidgetItem(aNewPlane.name);
586 QTableWidgetItem* aItem = new QTableWidgetItem(aPlane->getName().c_str());
587 QTableWidgetItem* aCheckItem = new QTableWidgetItem();
588 aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)?
589 Qt::Unchecked : Qt::Checked);
590 //aNewPlane.plane->setActive(myNonActivePlanes->checkState() != Qt::Checked);
591 aPlane->setActive(myNonActivePlanes->checkState() != Qt::Checked);
592 //if (aNewPlane.isAuto) {
593 if (aPlane->isAuto()) {
595 aItem->setCheckState(Qt::Checked);
596 // for (int i = 0; i < myPresentations.size(); i++) {
597 // getPrs(myPresentations.at(i))->AddClippingPlane(aNewPlane.plane);
600 aItem->setCheckState(Qt::Unchecked);
602 myPlanesList->setItem(aRow, 0, aItem);
603 myPlanesList->setItem(aRow, 1, aCheckItem);
604 //myPlanes.append(aNewPlane);
609 setPlanesVisible(myShowPlanes->checkState() == Qt::Checked);
612 myViewWindow->Repaint();
613 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
616 //*************************************************************************
617 void VisuGUI_ClippingPanel::onPlaneEdited()
619 disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
620 disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
621 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
622 //_PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj();
624 int aId = myPlaneDlg->planeId();
625 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
626 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aId);
627 // PlaneDef aPlane = myPlanes.at(myEditingPlanePos);
628 //updatePlane(aPlaneSObj, aPlane);
630 //QTableWidgetItem* aItem = myPlanesList->item(myEditingPlanePos, 0);
631 QTableWidgetItem* aItem = myPlanesList->item(aId, 0);
632 // if (aPlane.isAuto) {
633 if (aPlane->isAuto()) {
634 aItem->setCheckState(Qt::Checked);
636 QString name = aPlane->getName().c_str();
637 aItem->setText(name);
638 // _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
639 // _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aPlaneSObj);
640 // for (; aIter->More(); aIter->Next()) {
641 // _PTR(SObject) aObj = aIter->Value();
642 // VISU::DeleteSObject(myModule, aStudy, aObj);
644 VISU::UpdateObjBrowser(myModule);
646 aItem->setCheckState(Qt::Unchecked);
647 aItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable);
648 int aPrsNum = myPrsList->currentRow();
650 if (VISU_ClippingPlaneMgr::ContainsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane))
651 aItem->setCheckState(Qt::Checked);
658 //myPlanes.replace(myEditingPlanePos, aPlane);
659 setPlanesVisible(myShowPlanes->checkState() == Qt::Checked);
662 myViewWindow->Repaint();
663 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
666 //*************************************************************************
667 void VisuGUI_ClippingPanel::onEdit()
669 if (!isVISUDataReady()) return;
670 if (myPlaneDlg) return;
672 int aRow = myPlanesList->currentRow();
673 if (aRow < 0) return;
675 // const PlaneDef& aPlane = myPlanes.at(aRow);
677 myPlaneDlg = new VisuGUI_ClippingPlaneDlg(myModule);
678 //myPlaneDlg->setPlaneObj(aPlane.plane->getPlaneObject());
679 myPlaneDlg->setPlaneId(aRow);
680 connect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onPlaneEdited()));
681 connect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
682 //myEditingPlanePos = aRow;
686 //*************************************************************************
687 void VisuGUI_ClippingPanel::onNew()
689 if (!isVISUDataReady()) return;
691 if (myPlaneDlg) return;
693 myPlaneDlg = new VisuGUI_ClippingPlaneDlg(myModule);
694 connect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
695 connect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
699 //*************************************************************************
700 void VisuGUI_ClippingPanel::onPlaneDelete()
702 if (!isVISUDataReady()) return;
703 if (myPlaneDlg) return;
705 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
708 int aRow = myPlanesList->currentRow();
709 if (aRow < 0) return;
711 // const PlaneDef& aPlane = myPlanes.at(aRow);
712 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
713 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aRow);
714 QMessageBox::StandardButton aRes =
715 QMessageBox::warning(VISU::GetDesktop(myModule),
716 tr("TIT_DELETE_PLANE"),
717 tr("MSG_DELETE_PLANE").arg(aPlane->getName().c_str()),
718 QMessageBox::Yes | QMessageBox::No,
720 if (aRes == QMessageBox::Yes) {
721 aMgr.DeleteClippingPlane(aRow);
722 /* short aTag1 = aPlane.plane->getPlaneObject()->Tag();
723 for (int i = 0; i < myPresentations.size(); i++) {
724 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(i));
725 for (int j = aPrs->GetNumberOfClippingPlanes()-1; j > -1; j--) {
726 CutPlaneFunction* aPln = dynamic_cast<CutPlaneFunction*>(aPrs->GetClippingPlane(j));
728 short aTag2 = aPln->getPlaneObject()->Tag();
729 if (aTag1 == aTag2) {
730 aPrs->RemoveClippingPlane(j);
736 _PTR(SObject) aSObj = aPlane.plane->getPlaneObject();
737 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
738 aBuilder->RemoveObject(aSObj);
740 myPlanesList->removeRow(aRow);
741 //myPlanes.removeAt(aRow);
743 VISU::UpdateObjBrowser(myModule);
746 myViewWindow->Repaint();
750 //*************************************************************************
751 bool VisuGUI_ClippingPanel::isVISUDataReady()
753 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
755 _PTR(SComponent) aVisuSO = aStudy->FindComponent("VISU");
756 if (!aVisuSO) return false;
758 if(aStudy->GetProperties()->IsLocked()) return false;
762 //*************************************************************************
763 void VisuGUI_ClippingPanel::onApply()
765 if (myIsApplied) return;
769 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
770 for (i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
771 aMgr.GetClippingPlane(i)->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked));
773 // for(i = 0; i < myPlanes.size(); i++) {
774 // aPlane = myPlanes.at(i);
775 // aPlane.plane->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked));
779 int aPrsNum = myPrsList->currentRow();
781 // for(i = 0; i < myPlanes.size(); i++) {
782 for(i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
783 applyPlaneToPrs(i, aPrsNum, (myPlanesList->item(i, 0)->checkState() == Qt::Checked));
785 //myCheckedPlanes.clear();
786 VISU::UpdateObjBrowser(myModule);
789 myViewWindow->Repaint();
792 //*************************************************************************
793 void VisuGUI_ClippingPanel::setPlanesNonActive(bool theState)
796 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
797 //for (int i = 0; i < myPlanes.size(); i++) {
798 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
799 VISU_CutPlaneFunction* aPlane = 0;
800 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
801 //aPlane = myPlanes.at(i);
802 aPlane = aMgr.GetClippingPlane(i);
803 //aPlane.plane->setActive(!theState);
804 aPlane->setActive(!theState);
805 myPlanesList->item(i, 1)->setCheckState((theState)? Qt::Unchecked : Qt::Checked);
808 myViewWindow->Repaint();
809 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
812 //*************************************************************************
813 void VisuGUI_ClippingPanel::setPlanesVisible(bool theVisible)
815 if (!myViewWindow) return;
819 setPlanesVisible(false);
822 ComputeVisiblePropBounds(myViewWindow->getRenderer(), aBounds);
823 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
824 //for (int i = 0; i < myPlanes.size(); i++) {
825 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
826 //PreviewPlane* aPreview = new PreviewPlane(myViewWindow, myPlanes.at(i), aBounds);
827 PreviewPlane* aPreview = new PreviewPlane(myViewWindow, aMgr.GetClippingPlane(i), aBounds);
828 aPreview->setVisible(true);
829 myPreview.append(aPreview);
832 PreviewPlane* aPreview;
833 while (myPreview.size() > 0) {
834 aPreview = myPreview.last();
835 myPreview.removeLast();
839 myViewWindow->Repaint();
842 //*************************************************************************
843 void VisuGUI_ClippingPanel::onCancelDialog()
845 disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane()));
846 disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog()));
853 //*************************************************************************
854 void VisuGUI_ClippingPanel::onWindowActivated(SUIT_ViewWindow* theWindow)
856 setPlanesVisible(false);
857 myViewWindow = dynamic_cast<SVTK_ViewWindow*>(theWindow);
859 connect(myViewWindow, SIGNAL(destroyed(QObject*)), this, SLOT(onWindowDestroyed(QObject*)));
860 setPlanesVisible(myShowPlanes->checkState() == Qt::Checked);
863 //*************************************************************************
864 void VisuGUI_ClippingPanel::onCellChanged(int row, int col)
866 //PlaneDef aPlane = myPlanes.at(row);
867 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
868 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(row);
869 bool isChecked = (myPlanesList->item(row, col)->checkState() == Qt::Checked);
870 if (col == 1) { // activate column clicked
872 //aPlane.plane->setActive(isChecked);
873 aPlane->setActive(isChecked);
878 } else { // Plane checked
880 //if (aPlane.isAuto) return;
881 if (aPlane->isAuto()) return;
883 if (!isAutoApply()) {
884 //myCheckedPlanes.append(row);
888 int aPrsNum = myPrsList->currentRow();
889 if (aPrsNum < 0) return;
891 applyPlaneToPrs(row, aPrsNum, isChecked);
892 VISU::UpdateObjBrowser(myModule);
895 myViewWindow->Repaint();
898 //*************************************************************************
899 void VisuGUI_ClippingPanel::applyPlaneToPrs(int thePlaneNum, int thePrsNum, bool isChecked)
901 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrsNum));
902 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
903 if (isChecked) { // Apply
904 aMgr.ApplyClippingPlane(aPrs, thePlaneNum);
906 aMgr.DetachClippingPlane(aPrs, thePlaneNum);
908 /* PlaneDef aPlane = myPlanes.at(thePlaneNum);
909 _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) );
910 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
911 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrsNum));
912 _PTR(SObject) aSObject = aPlane.plane->getPlaneObject();
913 _PTR(SObject) aPrsSObj = aStudy->FindObjectID(aPrs->GetEntry());
915 if (!containsPlane(aPrs, aPlane)) {
916 aPrs->AddClippingPlane(aPlane.plane);
918 if(!aStudy->GetProperties()->IsLocked()) {
919 _PTR(SObject) aNewObj = aBuilder->NewObject(aSObject);
920 aBuilder->Addreference(aNewObj, aPrsSObj);
924 for (int i = 0; i < aPrs->GetNumberOfClippingPlanes(); i++) {
925 if (aPrs->GetClippingPlane(i) == aPlane.plane.GetPointer()) {
926 aPrs->RemoveClippingPlane(i);
930 if(!aStudy->GetProperties()->IsLocked()) {
931 _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aSObject);
932 for (; aIter->More(); aIter->Next()) {
933 _PTR(SObject) aRefObj = aIter->Value();
935 _PTR(SObject) aRefPrsObject;
936 if (aRefObj->ReferencedObject(aRefPrsObject)) {
937 if (QString(aRefPrsObject->GetID().c_str()) == QString(aPrs->GetEntry().c_str())) {
938 VISU::DeleteSObject(myModule, aStudy, aRefObj);
948 //*************************************************************************
949 /*bool VisuGUI_ClippingPanel::containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& thePlane)
951 //bool isContains = false;
952 for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) {
953 if (thePrs->GetClippingPlane(i) == thePlane.plane.GetPointer()) {
961 //*************************************************************************
962 void VisuGUI_ClippingPanel::onObjectDelete(QString theEntry)
964 disconnect(myPrsList, SIGNAL(currentRowChanged(int)), this, SLOT(onPrsSelected(int)));
966 foreach (QString aPrsEntry, myPresentations) {
967 VISU::Prs3d_i* aPrs = getPrs(aPrsEntry);
969 QString aID(aPrs->GetEntry().c_str());
970 if (aID == theEntry) {
971 myPresentations.removeAt(i);
972 myPrsList->takeItem(i);
978 connect(myPrsList, SIGNAL(currentRowChanged(int)), this, SLOT(onPrsSelected(int)));
979 onPrsSelected(myPrsList->currentRow());
982 //*************************************************************************
983 void VisuGUI_ClippingPanel::onPrsSelected(int thePrs)
985 if (thePrs < 0) return;
986 if (thePrs > myPresentations.size()) return;
987 disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
988 VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrs));
990 //QListOfPlanes::const_iterator aIt;
991 VISU_ClippingPlaneMgr& aMgr = getPlanesMgr();
992 for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) {
993 QTableWidgetItem* aItem = myPlanesList->item(i, 0);
994 VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i);
995 if (!aPlane->isAuto())
996 aItem->setCheckState(VISU_ClippingPlaneMgr::ContainsPlane(aPrs, aPlane)?
997 Qt::Checked : Qt::Unchecked);
999 /* for (aIt = myPlanes.begin(), i = 0; aIt != myPlanes.end(); ++aIt, i++) {
1000 QTableWidgetItem* aItem = myPlanesList->item(i, 0);
1001 const PlaneDef& aPlane = *aIt;
1003 aItem->setCheckState(containsPlane(aPrs, aPlane)? Qt::Checked : Qt::Unchecked);
1005 connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int)));
1008 //*************************************************************************
1009 bool VisuGUI_ClippingPanel::isAutoApply() const
1011 return myAutoApply->checkState() == Qt::Checked;
1015 //*************************************************************************
1016 VISU::Prs3d_i* VisuGUI_ClippingPanel::getPrs(QString theEntry)
1018 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(VISU::GetAppStudy(myModule),
1019 qPrintable(theEntry));
1020 return VISU::GetPrs3dFromBase(anObjectInfo.myBase);
1024 //*************************************************************************
1025 void VisuGUI_ClippingPanel::onHelp()
1027 QString aHelpFileName = "clipping_page.html";
1028 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1030 app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
1034 platform = "winapplication";
1036 platform = "application";
1038 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
1039 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1040 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
1041 QObject::tr("BUT_OK"));