From: vsv Date: Fri, 26 Sep 2008 05:12:10 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: TG_VISU_2008_Development_Finished X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=19741e85e889dbc09cd698311650303531dc03dc;p=modules%2Fvisu.git *** empty log message *** --- diff --git a/idl/VISU_Gen.idl b/idl/VISU_Gen.idl index ddabec98..f9ad0a1b 100644 --- a/idl/VISU_Gen.idl +++ b/idl/VISU_Gen.idl @@ -104,6 +104,18 @@ module VISU { TALL }; + /* Clipping planes management */ + struct ClippingPlane { + double X; + double Y; + double Z; + double dX; + double dY; + double dZ; + boolean isAuto; + string name; + }; + interface Base { /*! * Returns ID of the object. @@ -2112,6 +2124,37 @@ module VISU { * Get or create %ColoredPrs3dCache object. */ ColoredPrs3dCache GetColoredPrs3dCache(in SALOMEDS::Study theStudy); + + + /* Clipping planes management */ + + /*Create a clipping plane and return its ID (position in corresponded array) + Id of clipping plane could be changed after deletion of other clipping plane + */ + long CreateClippingPlane(in double X, in double Y, in double Z, + in double dX, in double dY, in double dZ, + in boolean auto, in string name); + + void EditClippingPlane(in long id, in double X, in double Y, in double Z, + in double dX, in double dY, in double dZ, + in boolean auto, in string name); + + /* Returns clipping plane by its Id */ + ClippingPlane GetClippingPlane(in long id); + + /* Deletes clipping plane by its Id */ + boolean DeleteClippingPlane(in long id); + + /* Applyes a clipping plane with Id to presentation thePrs */ + boolean ApplyClippingPlane(in Prs3d thePrs, in long id); + + /* Detaches a clipping plane with Id from presentation thePrs */ + boolean DetachClippingPlane(in Prs3d thePrs, in long id); + + + /* Get number of clipping planes */ + long GetClippingPlanesNb(); + }; /*! \brief %View interface @@ -2644,6 +2687,8 @@ module VISU { */ void Destroy(in View theView); }; + + }; #endif diff --git a/src/ENGINE/VISU_Engine_i.cc b/src/ENGINE/VISU_Engine_i.cc index 80b53607..4f60f1f3 100644 --- a/src/ENGINE/VISU_Engine_i.cc +++ b/src/ENGINE/VISU_Engine_i.cc @@ -459,4 +459,50 @@ namespace VISU{ { return myVisuGen->GetColoredPrs3dCache(theStudy); } + + + + CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name) + { + return myVisuGen->CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name); + } + + + void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name) + { + myVisuGen->EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name); + } + + /* Returns clipping plane by its Id */ + VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id) + { + return myVisuGen->GetClippingPlane(id); + } + + /* Deletes clipping plane by its Id */ + CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id) + { + return myVisuGen->DeleteClippingPlane(id); + } + + /* Applyes a clipping plane with Id to presentation thePrs */ + CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id) + { + return myVisuGen->ApplyClippingPlane(thePrs, id); + } + + CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id) + { + return myVisuGen->DetachClippingPlane(thePrs, id); + } + + /* Get number of clipping planes */ + CORBA::Long VISU_Gen_i::GetClippingPlanesNb() + { + return myVisuGen->GetClippingPlanesNb(); + } }; diff --git a/src/ENGINE/VISU_Engine_i.hh b/src/ENGINE/VISU_Engine_i.hh index 8c5964c6..fdc1c3c8 100644 --- a/src/ENGINE/VISU_Engine_i.hh +++ b/src/ENGINE/VISU_Engine_i.hh @@ -220,6 +220,31 @@ namespace VISU virtual VISU::ColoredPrs3dCache_ptr GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy); + + + + virtual CORBA::Long CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name); + + virtual void EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name); + + /* Returns clipping plane by its Id */ + virtual VISU::ClippingPlane* GetClippingPlane(CORBA::Long id); + + /* Deletes clipping plane by its Id */ + virtual CORBA::Boolean DeleteClippingPlane(CORBA::Long id); + + /* Applyes a clipping plane with Id to presentation thePrs */ + virtual CORBA::Boolean ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id); + + /* Detaches a clipping plane with Id from presentation thePrs */ + virtual CORBA::Boolean DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id); + + /* Get number of clipping planes */ + virtual CORBA::Long GetClippingPlanesNb(); }; }; diff --git a/src/VISUGUI/VisuGUI_ClippingPanel.cxx b/src/VISUGUI/VisuGUI_ClippingPanel.cxx index 3cc67c33..5b76f650 100644 --- a/src/VISUGUI/VisuGUI_ClippingPanel.cxx +++ b/src/VISUGUI/VisuGUI_ClippingPanel.cxx @@ -27,6 +27,9 @@ #include +#include +#include + #include #include #include @@ -37,6 +40,8 @@ #include #include + + #include #include #include @@ -57,7 +62,7 @@ -#define SIZEFACTOR 1.5 +#define SIZEFACTOR 1.1 #define PRINT3(MARK, VAL) printf("#### %s x=%f, y=%f, z=%f\n", MARK, VAL[0], VAL[1], VAL[2]); @@ -80,7 +85,10 @@ void AdjustBounds(const double bounds[6], double newBounds[6], double center[3]) //**************************************************************** -PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds): +//PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds): +PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, + VISU_CutPlaneFunction* thePlane, + const double* theBounds): myWindow(theWindow), myBounds(theBounds) { @@ -89,7 +97,8 @@ PreviewPlane::PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, AdjustBounds(myBounds, aBound, aCenter); - myPlane = thePlane.plane; + //myPlane = thePlane.plane; + myPlane = thePlane; myBox = vtkImageData::New(); myBox->SetDimensions(2, 2, 2); @@ -155,7 +164,7 @@ PreviewPlane::~PreviewPlane() //**************************************************************** //**************************************************************** //**************************************************************** -CutPlaneFunction* CutPlaneFunction::New() +/*CutPlaneFunction* CutPlaneFunction::New() { return new CutPlaneFunction(); } @@ -191,7 +200,7 @@ CutPlaneFunction::CutPlaneFunction(): CutPlaneFunction::~CutPlaneFunction() { } - +*/ //**************************************************************** @@ -374,13 +383,46 @@ QStringList VisuGUI_ClippingPanel::getPrsList(_PTR(Study) theStudy, return aList; } +//************************************************************************* +VISU_ClippingPlaneMgr& VisuGUI_ClippingPanel::getPlanesMgr() const +{ + return VISU::GetVisuGen(myModule)->GetClippingPlaneMgr(); +} + //************************************************************************* void VisuGUI_ClippingPanel::fillPlanesList() { disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); myPlanesList->clear(); - myPlanes.clear(); _PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule)); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) { + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i); + myPlanesList->insertRow(i); + QTableWidgetItem* aItem = new QTableWidgetItem(aPlane->getName().c_str()); + QTableWidgetItem* aCheckItem = new QTableWidgetItem(); + aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)? + Qt::Unchecked : Qt::Checked); + if (aPlane->isAuto()) { // If this is Auto plane + aItem->setFlags(0); + aItem->setCheckState(Qt::Checked); + } else { // if it is not auto + aItem->setCheckState(Qt::Unchecked); + // Check current presentation + int aPrsNum = myPrsList->currentRow(); + if (aPrsNum >= 0) { + if (VISU_ClippingPlaneMgr::ContainsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane)) + aItem->setCheckState(Qt::Checked); + } + } + myPlanesList->setItem(i, 0, aItem); + myPlanesList->setItem(i, 1, aCheckItem); + } + myPlanesList->setHorizontalHeaderLabels(QString(tr("PLANES_TABLE_TITLES")).split(",")); + if (myViewWindow) + myViewWindow->Repaint(); + //myPlanes.clear(); + /*_PTR(Study) aStudy = VISU::GetCStudy(VISU::GetAppStudy(myModule)); _PTR(SObject) aFolder; if (VISU::getClippingPlanesFolder(aStudy, aFolder)) { _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aFolder); @@ -430,7 +472,7 @@ void VisuGUI_ClippingPanel::fillPlanesList() } myPlanesList->setHorizontalHeaderLabels(QString(tr("PLANES_TABLE_TITLES")).split(",")); if (myViewWindow) - myViewWindow->Repaint(); + myViewWindow->Repaint();*/ connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); } @@ -469,16 +511,29 @@ void VisuGUI_ClippingPanel::onWindowDestroyed(QObject* theWnd) void VisuGUI_ClippingPanel::onPresentationCreate(VISU::Prs3d_i* thePrs) { myPrsList->addItem(getPrsName(thePrs)); - myPresentations.append(thePrs->GetEntry().c_str()); - for (int i = 0; i < myPlanes.size(); i++) { + string aEntry = thePrs->GetEntry(); + if (aEntry.length() == 0) { + VISU::ColoredPrs3d_i* aColPrs = dynamic_cast(thePrs); + if (aColPrs) + aEntry = aColPrs->GetHolderEntry(); + } + + myPresentations.append(aEntry.c_str()); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) { + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i); + if (aPlane->isAuto()) + aMgr.ApplyClippingPlane(thePrs, i); + } + /* for (int i = 0; i < myPlanes.size(); i++) { const PlaneDef& aPlane = myPlanes.at(i); if (aPlane.isAuto) thePrs->AddClippingPlane(aPlane.plane); - } + }*/ } //************************************************************************* -PlaneDef VisuGUI_ClippingPanel::createEmptyPlane() +/*PlaneDef VisuGUI_ClippingPanel::createEmptyPlane() { PlaneDef aPlane; aPlane.name = QString("Plane"); @@ -488,10 +543,10 @@ PlaneDef VisuGUI_ClippingPanel::createEmptyPlane() aPlane.plane->SetNormal(0.,0.,1.); aPlane.isAuto = true; return aPlane; -} +}*/ //************************************************************************* -void VisuGUI_ClippingPanel::updatePlane(_PTR(SObject) theObject, PlaneDef& thePlane) +/*void VisuGUI_ClippingPanel::updatePlane(_PTR(SObject) theObject, PlaneDef& thePlane) { thePlane.name = QString(theObject->GetName().c_str()); thePlane.plane->setPlaneObject(theObject); @@ -506,7 +561,7 @@ void VisuGUI_ClippingPanel::updatePlane(_PTR(SObject) theObject, PlaneDef& thePl _PTR(AttributeInteger) aFlag(anAttr); thePlane.isAuto = (aFlag->Value() == 1); } -} +}*/ //************************************************************************* void VisuGUI_ClippingPanel::onNewPlane() @@ -514,29 +569,36 @@ void VisuGUI_ClippingPanel::onNewPlane() disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane())); disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog())); disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); - _PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj(); + //_PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj(); + int aId = myPlaneDlg->planeId(); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); - PlaneDef aNewPlane = createEmptyPlane(); - updatePlane(aPlaneSObj, aNewPlane); + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aId); + //PlaneDef aNewPlane = createEmptyPlane(); + //updatePlane(aPlaneSObj, aNewPlane); int aRow = myPlanesList->rowCount(); myPlanesList->insertRow(aRow); - QTableWidgetItem* aItem = new QTableWidgetItem(aNewPlane.name); + //QTableWidgetItem* aItem = new QTableWidgetItem(aNewPlane.name); + QTableWidgetItem* aItem = new QTableWidgetItem(aPlane->getName().c_str()); QTableWidgetItem* aCheckItem = new QTableWidgetItem(); - aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)? Qt::Unchecked : Qt::Checked); - aNewPlane.plane->setActive(myNonActivePlanes->checkState() != Qt::Checked); - if (aNewPlane.isAuto) { + aCheckItem->setCheckState((myNonActivePlanes->checkState() == Qt::Checked)? + Qt::Unchecked : Qt::Checked); + //aNewPlane.plane->setActive(myNonActivePlanes->checkState() != Qt::Checked); + aPlane->setActive(myNonActivePlanes->checkState() != Qt::Checked); + //if (aNewPlane.isAuto) { + if (aPlane->isAuto()) { aItem->setFlags(0); aItem->setCheckState(Qt::Checked); - for (int i = 0; i < myPresentations.size(); i++) { - getPrs(myPresentations.at(i))->AddClippingPlane(aNewPlane.plane); - } +// for (int i = 0; i < myPresentations.size(); i++) { +// getPrs(myPresentations.at(i))->AddClippingPlane(aNewPlane.plane); +// } } else { aItem->setCheckState(Qt::Unchecked); } myPlanesList->setItem(aRow, 0, aItem); myPlanesList->setItem(aRow, 1, aCheckItem); - myPlanes.append(aNewPlane); + //myPlanes.append(aNewPlane); delete myPlaneDlg; myPlaneDlg = 0; @@ -554,37 +616,41 @@ void VisuGUI_ClippingPanel::onPlaneEdited() disconnect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onNewPlane())); disconnect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog())); disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); - _PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj(); - - PlaneDef aPlane = myPlanes.at(myEditingPlanePos); - updatePlane(aPlaneSObj, aPlane); - - QTableWidgetItem* aItem = myPlanesList->item(myEditingPlanePos, 0); - if (aPlane.isAuto) { + //_PTR(SObject) aPlaneSObj = myPlaneDlg->getPlaneObj(); + + int aId = myPlaneDlg->planeId(); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aId); + // PlaneDef aPlane = myPlanes.at(myEditingPlanePos); + //updatePlane(aPlaneSObj, aPlane); + + //QTableWidgetItem* aItem = myPlanesList->item(myEditingPlanePos, 0); + QTableWidgetItem* aItem = myPlanesList->item(aId, 0); + // if (aPlane.isAuto) { + if (aPlane->isAuto()) { aItem->setCheckState(Qt::Checked); aItem->setFlags(0); - _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) ); - _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aPlaneSObj); - for (; aIter->More(); aIter->Next()) { - _PTR(SObject) aObj = aIter->Value(); - VISU::DeleteSObject(myModule, aStudy, aObj); - } - VISU::UpdateObjBrowser(myModule); +// _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) ); +// _PTR(ChildIterator) aIter = aStudy->NewChildIterator(aPlaneSObj); +// for (; aIter->More(); aIter->Next()) { +// _PTR(SObject) aObj = aIter->Value(); +// VISU::DeleteSObject(myModule, aStudy, aObj); +// } + VISU::UpdateObjBrowser(myModule); } else { aItem->setCheckState(Qt::Unchecked); aItem->setFlags(Qt::ItemIsEnabled | Qt::ItemIsUserCheckable); int aPrsNum = myPrsList->currentRow(); if (aPrsNum >= 0) { - if (containsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane)) + if (VISU_ClippingPlaneMgr::ContainsPlane(getPrs(myPresentations.at(aPrsNum)), aPlane)) aItem->setCheckState(Qt::Checked); } } - aItem->setText(aPlane.name); delete myPlaneDlg; myPlaneDlg = 0; - myPlanes.replace(myEditingPlanePos, aPlane); + //myPlanes.replace(myEditingPlanePos, aPlane); setPlanesVisible(myShowPlanes->checkState() == Qt::Checked); if (myViewWindow) @@ -601,13 +667,14 @@ void VisuGUI_ClippingPanel::onEdit() int aRow = myPlanesList->currentRow(); if (aRow < 0) return; - const PlaneDef& aPlane = myPlanes.at(aRow); + // const PlaneDef& aPlane = myPlanes.at(aRow); myPlaneDlg = new VisuGUI_ClippingPlaneDlg(myModule); - myPlaneDlg->setPlaneObj(aPlane.plane->getPlaneObject()); + //myPlaneDlg->setPlaneObj(aPlane.plane->getPlaneObject()); + myPlaneDlg->setPlaneId(aRow); connect(myPlaneDlg, SIGNAL(accepted()), this, SLOT(onPlaneEdited())); connect(myPlaneDlg, SIGNAL(rejected()), this, SLOT(onCancelDialog())); - myEditingPlanePos = aRow; + //myEditingPlanePos = aRow; myPlaneDlg->show(); } @@ -636,14 +703,18 @@ void VisuGUI_ClippingPanel::onPlaneDelete() int aRow = myPlanesList->currentRow(); if (aRow < 0) return; - const PlaneDef& aPlane = myPlanes.at(aRow); - QMessageBox::StandardButton aRes = QMessageBox::warning(VISU::GetDesktop(myModule), - tr("TIT_DELETE_PLANE"), - tr("MSG_DELETE_PLANE").arg(aPlane.name), - QMessageBox::Yes | QMessageBox::No, - QMessageBox::No); + // const PlaneDef& aPlane = myPlanes.at(aRow); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(aRow); + QMessageBox::StandardButton aRes = + QMessageBox::warning(VISU::GetDesktop(myModule), + tr("TIT_DELETE_PLANE"), + tr("MSG_DELETE_PLANE").arg(aPlane->getName().c_str()), + QMessageBox::Yes | QMessageBox::No, + QMessageBox::No); if (aRes == QMessageBox::Yes) { - short aTag1 = aPlane.plane->getPlaneObject()->Tag(); + aMgr.DeleteClippingPlane(aRow); + /* short aTag1 = aPlane.plane->getPlaneObject()->Tag(); for (int i = 0; i < myPresentations.size(); i++) { VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(i)); for (int j = aPrs->GetNumberOfClippingPlanes()-1; j > -1; j--) { @@ -660,9 +731,9 @@ void VisuGUI_ClippingPanel::onPlaneDelete() _PTR(SObject) aSObj = aPlane.plane->getPlaneObject(); _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); aBuilder->RemoveObject(aSObj); - + */ myPlanesList->removeRow(aRow); - myPlanes.removeAt(aRow); + //myPlanes.removeAt(aRow); VISU::UpdateObjBrowser(myModule); @@ -688,17 +759,22 @@ void VisuGUI_ClippingPanel::onApply() { if (myIsApplied) return; - PlaneDef aPlane; + //PlaneDef aPlane; int i; - for(i = 0; i < myPlanes.size(); i++) { - aPlane = myPlanes.at(i); - aPlane.plane->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked)); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + for (i = 0; i < aMgr.GetClippingPlanesNb(); i++) { + aMgr.GetClippingPlane(i)->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked)); } +// for(i = 0; i < myPlanes.size(); i++) { +// aPlane = myPlanes.at(i); +// aPlane.plane->setActive((myPlanesList->item(i, 1)->checkState() == Qt::Checked)); +// } myIsApplied = true; int aPrsNum = myPrsList->currentRow(); if (aPrsNum > -1) { - for(i = 0; i < myPlanes.size(); i++) { + // for(i = 0; i < myPlanes.size(); i++) { + for(i = 0; i < aMgr.GetClippingPlanesNb(); i++) { applyPlaneToPrs(i, aPrsNum, (myPlanesList->item(i, 0)->checkState() == Qt::Checked)); } //myCheckedPlanes.clear(); @@ -711,11 +787,16 @@ void VisuGUI_ClippingPanel::onApply() //************************************************************************* void VisuGUI_ClippingPanel::setPlanesNonActive(bool theState) { - PlaneDef aPlane; + //PlaneDef aPlane; disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); - for (int i = 0; i < myPlanes.size(); i++) { - aPlane = myPlanes.at(i); - aPlane.plane->setActive(!theState); + //for (int i = 0; i < myPlanes.size(); i++) { + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + VISU_CutPlaneFunction* aPlane = 0; + for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) { + //aPlane = myPlanes.at(i); + aPlane = aMgr.GetClippingPlane(i); + //aPlane.plane->setActive(!theState); + aPlane->setActive(!theState); myPlanesList->item(i, 1)->setCheckState((theState)? Qt::Unchecked : Qt::Checked); } if (myViewWindow) @@ -734,8 +815,11 @@ void VisuGUI_ClippingPanel::setPlanesVisible(bool theVisible) double aBounds[6]; ComputeVisiblePropBounds(myViewWindow->getRenderer(), aBounds); - for (int i = 0; i < myPlanes.size(); i++) { - PreviewPlane* aPreview = new PreviewPlane(myViewWindow, myPlanes.at(i), aBounds); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + //for (int i = 0; i < myPlanes.size(); i++) { + for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) { + //PreviewPlane* aPreview = new PreviewPlane(myViewWindow, myPlanes.at(i), aBounds); + PreviewPlane* aPreview = new PreviewPlane(myViewWindow, aMgr.GetClippingPlane(i), aBounds); aPreview->setVisible(true); myPreview.append(aPreview); } @@ -774,18 +858,22 @@ void VisuGUI_ClippingPanel::onWindowActivated(SUIT_ViewWindow* theWindow) //************************************************************************* void VisuGUI_ClippingPanel::onCellChanged(int row, int col) { - PlaneDef aPlane = myPlanes.at(row); + //PlaneDef aPlane = myPlanes.at(row); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(row); bool isChecked = (myPlanesList->item(row, col)->checkState() == Qt::Checked); if (col == 1) { // activate column clicked if (isAutoApply()) - aPlane.plane->setActive(isChecked); + //aPlane.plane->setActive(isChecked); + aPlane->setActive(isChecked); else { myIsApplied = false; return; } } else { // Plane checked - if (aPlane.isAuto) return; + //if (aPlane.isAuto) return; + if (aPlane->isAuto()) return; if (!isAutoApply()) { //myCheckedPlanes.append(row); @@ -805,7 +893,14 @@ void VisuGUI_ClippingPanel::onCellChanged(int row, int col) //************************************************************************* void VisuGUI_ClippingPanel::applyPlaneToPrs(int thePlaneNum, int thePrsNum, bool isChecked) { - PlaneDef aPlane = myPlanes.at(thePlaneNum); + VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrsNum)); + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + if (isChecked) { // Apply + aMgr.ApplyClippingPlane(aPrs, thePlaneNum); + } else { // Detach + aMgr.DetachClippingPlane(aPrs, thePlaneNum); + } + /* PlaneDef aPlane = myPlanes.at(thePlaneNum); _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) ); _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder(); VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrsNum)); @@ -842,11 +937,11 @@ void VisuGUI_ClippingPanel::applyPlaneToPrs(int thePlaneNum, int thePrsNum, bool } } } - } + }*/ } //************************************************************************* -bool VisuGUI_ClippingPanel::containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& thePlane) +/*bool VisuGUI_ClippingPanel::containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& thePlane) { //bool isContains = false; for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) { @@ -855,7 +950,7 @@ bool VisuGUI_ClippingPanel::containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& } } return false; -} +}*/ //************************************************************************* @@ -883,16 +978,25 @@ void VisuGUI_ClippingPanel::onObjectDelete(QString theEntry) void VisuGUI_ClippingPanel::onPrsSelected(int thePrs) { if (thePrs < 0) return; + if (thePrs > myPresentations.size()) return; disconnect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); VISU::Prs3d_i* aPrs = getPrs(myPresentations.at(thePrs)); - QListOfPlanes::const_iterator aIt; - int i = 0; - for (aIt = myPlanes.begin(), i = 0; aIt != myPlanes.end(); ++aIt, i++) { + if (!aPrs) return; + //QListOfPlanes::const_iterator aIt; + VISU_ClippingPlaneMgr& aMgr = getPlanesMgr(); + for (int i = 0; i < aMgr.GetClippingPlanesNb(); i++) { + QTableWidgetItem* aItem = myPlanesList->item(i, 0); + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(i); + if (!aPlane->isAuto()) + aItem->setCheckState(VISU_ClippingPlaneMgr::ContainsPlane(aPrs, aPlane)? + Qt::Checked : Qt::Unchecked); + } + /* for (aIt = myPlanes.begin(), i = 0; aIt != myPlanes.end(); ++aIt, i++) { QTableWidgetItem* aItem = myPlanesList->item(i, 0); const PlaneDef& aPlane = *aIt; if (!aPlane.isAuto) aItem->setCheckState(containsPlane(aPrs, aPlane)? Qt::Checked : Qt::Unchecked); - } + }*/ connect(myPlanesList, SIGNAL(cellChanged(int,int)), this, SLOT(onCellChanged(int,int))); } diff --git a/src/VISUGUI/VisuGUI_ClippingPanel.h b/src/VISUGUI/VisuGUI_ClippingPanel.h index fd145af3..53d23cb8 100644 --- a/src/VISUGUI/VisuGUI_ClippingPanel.h +++ b/src/VISUGUI/VisuGUI_ClippingPanel.h @@ -36,6 +36,7 @@ class vtkCutter; #include "VISU_Prs3d_i.hh" #include "VisuGUI_Panel.h" //#include +#include #include #include @@ -43,7 +44,8 @@ class vtkCutter; #include -class CutPlaneFunction: public vtkPlane + +/*class CutPlaneFunction: public vtkPlane { public: static CutPlaneFunction* New(); @@ -76,12 +78,13 @@ struct PlaneDef bool isAuto; QString name; }; - +*/ class PreviewPlane { public: - PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds); + //PreviewPlane(SVTK_ViewWindow* theWindow, const PlaneDef& thePlane, const double* theBounds); + PreviewPlane(SVTK_ViewWindow* theWindow, VISU_CutPlaneFunction* thePlane, const double* theBounds); ~PreviewPlane(); void setVisible(bool theVisible) @@ -99,7 +102,7 @@ private: }; -typedef QList QListOfPlanes; +//typedef QList QListOfPlanes; typedef QList ListOfvtkPlanes; typedef QList ListOfPreview; @@ -148,10 +151,12 @@ private slots: bool isAutoApply() const; + VISU_ClippingPlaneMgr& getPlanesMgr() const; + - void updatePlane(_PTR(SObject) theObject, PlaneDef& thePlane); - PlaneDef createEmptyPlane(); - static bool containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& thePlane); + //void updatePlane(_PTR(SObject) theObject, PlaneDef& thePlane); + //PlaneDef createEmptyPlane(); + //static bool containsPlane(VISU::Prs3d_i* thePrs, const PlaneDef& thePlane); QString getPrsName(VISU::Prs3d_i* thePrs); @@ -172,13 +177,13 @@ private slots: QCheckBox* myNonActivePlanes; QCheckBox* myAutoApply; - QListOfPlanes myPlanes; + //QListOfPlanes myPlanes; // QList myPresentations; QStringList myPresentations; // Stores entries of presentation objects ListOfPreview myPreview; VisuGUI_ClippingPlaneDlg* myPlaneDlg; - int myEditingPlanePos; + //int myEditingPlanePos; SVTK_ViewWindow* myViewWindow; bool myIsApplied; //QList myCheckedPlanes; diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneDlg.cxx b/src/VISUGUI/VisuGUI_ClippingPlaneDlg.cxx index b322b8b6..972a7a2b 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneDlg.cxx +++ b/src/VISUGUI/VisuGUI_ClippingPlaneDlg.cxx @@ -23,6 +23,8 @@ #include "VisuGUI_Tools.h" #include "VisuGUI_ViewTools.h" +#include + #include #include #include @@ -46,7 +48,7 @@ #include -#define SIZEFACTOR 1.5 +#define SIZEFACTOR 1.1 @@ -59,7 +61,8 @@ VisuGUI_ClippingPlaneDlg::VisuGUI_ClippingPlaneDlg(VisuGUI* theModule) myModule(theModule), myCallback( vtkCallbackCommand::New() ), myPreviewWidget(0), - myViewWindow(0) + myViewWindow(0), + myPlaneId(-1) { myViewWindow = VISU::GetActiveViewWindow(myModule); ComputeVisiblePropBounds(myViewWindow->getRenderer(), myBounds); @@ -264,7 +267,34 @@ vtkImplicitPlaneWidget* VisuGUI_ClippingPlaneDlg::createPreviewWidget() //**************************************************************** -void VisuGUI_ClippingPlaneDlg::setPlaneObj(_PTR(SObject) thePlaneObj) +void VisuGUI_ClippingPlaneDlg::setPlaneId(int theId) +{ + myPlaneId = theId; + VISU_ClippingPlaneMgr& aMgr = VISU::GetVisuGen(myModule)->GetClippingPlaneMgr(); + + VISU_CutPlaneFunction* aPlane = aMgr.GetClippingPlane(myPlaneId); + if (aPlane) { + myNameEdt->setText(QString(aPlane->getName().c_str())); + double aOrigin[3], aDir[3]; + aPlane->GetOrigin(aOrigin); + aPlane->GetNormal(aDir); + + myXOrigin->setValue(aOrigin[0]); + myYOrigin->setValue(aOrigin[1]); + myZOrigin->setValue(aOrigin[2]); + myPreviewWidget->SetOrigin(aOrigin); + + myXDir->setValue(aDir[0]); + myYDir->setValue(aDir[1]); + myZDir->setValue(aDir[2]); + + myPreviewWidget->SetNormal(aDir); + + myAutoApply->setCheckState((aPlane->isAuto())? Qt::Checked : Qt::Unchecked); + myViewWindow->Repaint(); + } +} +/*void VisuGUI_ClippingPlaneDlg::setPlaneObj(_PTR(SObject) thePlaneObj) { myPlaneObj = thePlaneObj; @@ -291,12 +321,29 @@ void VisuGUI_ClippingPlaneDlg::setPlaneObj(_PTR(SObject) thePlaneObj) } myViewWindow->Repaint(); -} +}*/ //**************************************************************** void VisuGUI_ClippingPlaneDlg::accept() { _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) ); + if(!aStudy->GetProperties()->IsLocked()) { + VISU_ClippingPlaneMgr& aMgr = VISU::GetVisuGen(myModule)->GetClippingPlaneMgr(); + if (myPlaneId == -1) { // Create a New plane + myPlaneId = aMgr.CreateClippingPlane(myXOrigin->value(), myYOrigin->value(), myZOrigin->value(), + myXDir->value(), myYDir->value(), myZDir->value(), + myAutoApply->checkState() == Qt::Checked, + qPrintable(myNameEdt->text())); + } else { // Edit Plane + aMgr.EditClippingPlane(myPlaneId, + myXOrigin->value(), myYOrigin->value(), myZOrigin->value(), + myXDir->value(), myYDir->value(), myZDir->value(), + myAutoApply->checkState() == Qt::Checked, + qPrintable(myNameEdt->text())); + } + VISU::UpdateObjBrowser(myModule); + } + /* _PTR(Study) aStudy = VISU::GetCStudy( VISU::GetAppStudy( myModule ) ); if(!aStudy->GetProperties()->IsLocked()) { _PTR(SObject) aFolder; if (VISU::getClippingPlanesFolder(aStudy, aFolder)) { @@ -335,7 +382,7 @@ void VisuGUI_ClippingPlaneDlg::accept() VISU::UpdateObjBrowser(myModule); } - } + }*/ QDialog::accept(); } diff --git a/src/VISUGUI/VisuGUI_ClippingPlaneDlg.h b/src/VISUGUI/VisuGUI_ClippingPlaneDlg.h index 49e60c0f..e443c790 100644 --- a/src/VISUGUI/VisuGUI_ClippingPlaneDlg.h +++ b/src/VISUGUI/VisuGUI_ClippingPlaneDlg.h @@ -47,8 +47,10 @@ public: void setOrigin(double theVal[3]); void setDirection(double theVal[3]); - void setPlaneObj(_PTR(SObject) thePlaneObj); - _PTR(SObject) getPlaneObj() const { return myPlaneObj; } + void setPlaneId(int theId); + int planeId() const { return myPlaneId; } + //void setPlaneObj(_PTR(SObject) thePlaneObj); + //_PTR(SObject) getPlaneObj() const { return myPlaneObj; } protected slots: virtual void accept(); @@ -58,7 +60,7 @@ private slots: void onValueChanged(); private: - void setEmptyPlane(PlaneDef& thePlane) const; + //void setEmptyPlane(PlaneDef& thePlane) const; vtkImplicitPlaneWidget* createPreviewWidget(); @@ -84,7 +86,8 @@ private slots: vtkSmartPointer myCallback; double myBounds[6]; - _PTR(SObject) myPlaneObj; + //_PTR(SObject) myPlaneObj; + int myPlaneId; }; #endif diff --git a/src/VISU_I/Makefile.am b/src/VISU_I/Makefile.am index 1b0dbd99..1258a254 100644 --- a/src/VISU_I/Makefile.am +++ b/src/VISU_I/Makefile.am @@ -51,7 +51,8 @@ salomeinclude_HEADERS = \ VISU_TimeAnimation.h \ VISU_ScalarMapOnDeformedShape_i.hh \ VISU_ColoredPrs3dFactory.hh \ - SALOME_GenericObjPointer.hh + SALOME_GenericObjPointer.hh \ + VISU_ClippingPlaneMgr.hxx libVISUEngineImpl_la_SOURCES = \ VISUConfig.cc \ @@ -83,7 +84,8 @@ libVISUEngineImpl_la_SOURCES = \ VISU_View_i.cc \ VISU_Table_i.cc \ VISU_DumpPython.cc \ - SALOME_GenericObjPointer.cc + SALOME_GenericObjPointer.cc \ + VISU_ClippingPlaneMgr.cxx MOC_FILES = VISU_TimeAnimation_moc.cxx nodist_libVISUEngineImpl_la_SOURCES= $(MOC_FILES) diff --git a/src/VISU_I/VISU_ClippingPlaneMgr.cxx b/src/VISU_I/VISU_ClippingPlaneMgr.cxx new file mode 100644 index 00000000..bcdf285e --- /dev/null +++ b/src/VISU_I/VISU_ClippingPlaneMgr.cxx @@ -0,0 +1,489 @@ +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com + + +#include "VISU_ClippingPlaneMgr.hxx" +#include "VISU_ColoredPrs3dHolder_i.hh" + +//#include CORBA_SERVER_HEADER(SALOMEDS) +//#include CORBA_SERVER_HEADER(SALOMEDS_Attributes) + +#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_AttributeName.hxx" +#include "SALOMEDSClient_AttributeSequenceOfReal.hxx" +#include "SALOMEDSClient_AttributeInteger.hxx" + + +#include + + +#define CLIP_PLANES_FOLDER "Clipping Planes" + + +//************************************************************* +VISU_ClippingPlaneMgr::VISU_ClippingPlaneMgr() +{ + myPlanes = vtkImplicitFunctionCollection::New(); +} + +//************************************************************* +VISU_ClippingPlaneMgr::~VISU_ClippingPlaneMgr() +{ + myPlanes->Delete(); +} + +//************************************************************* +void VISU_ClippingPlaneMgr::SetStudy(_PTR(Study) theStudy) +{ + myStudy = theStudy; + myPlanes->RemoveAllItems(); + _PTR(SObject) aFolder = GetClippingPlanesFolder(false); + if (aFolder) { + _PTR(ChildIterator) aIter = myStudy->NewChildIterator(aFolder); + int i; + for (i = 0; aIter->More(); aIter->Next(), i++) { // For each plane + _PTR(SObject) aSObject = aIter->Value(); + VISU_CutPlaneFunction* aPlane = VISU_CutPlaneFunction::New(); + aPlane->setPlaneObject(aSObject); + aPlane->setName(aSObject->GetName()); + + _PTR(GenericAttribute) anAttr; + if (aSObject->FindAttribute(anAttr, "AttributeSequenceOfReal")) { + _PTR(AttributeSequenceOfReal) aArray(anAttr); + aPlane->SetOrigin(aArray->Value(1), aArray->Value(2), aArray->Value(3)); + aPlane->SetNormal(aArray->Value(4), aArray->Value(5), aArray->Value(6)); + } + if (aSObject->FindAttribute(anAttr, "AttributeInteger")) { + _PTR(AttributeInteger) aFlag(anAttr); + aPlane->setAuto(aFlag->Value() == 1); + } else + aPlane->setAuto(false); + + applyPlaneToAll(aPlane); + myPlanes->AddItem(aPlane); + } + } +} + + +void VISU_ClippingPlaneMgr::applyPlaneToAll(VISU_CutPlaneFunction* thePlane) +{ + _PTR(SComponent) aVisuSO = myStudy->FindComponent("VISU"); + _PTR(ChildIterator) aChildIter = myStudy->NewChildIterator(aVisuSO); + for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { + _PTR(SObject) aSObject = aChildIter->Value(); + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + if(VISU::Base_i* aBase = dynamic_cast(VISU::GetServant(anObject).in())) { + VISU::Prs3d_i* aPrs; + if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){ + CORBA::Object_var anObject = aBase->_this(); + VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject); + VISU::Prs3d_var aPrs3d = aHolder->GetDevice(); + aPrs = dynamic_cast(VISU::GetServant(aPrs3d).in()); + } else { + aPrs = dynamic_cast(aBase); + } + if (aPrs) { + if (!ContainsPlane(aPrs, thePlane)) { + if (thePlane->isAuto()) + aPrs->AddClippingPlane(thePlane); + else { + string aPrsEntry = aPrs->GetEntry(); + if (aPrsEntry.length() == 0) { + VISU::ColoredPrs3d_i* aColPrs = dynamic_cast(aPrs); + if (aColPrs) + aPrsEntry = aColPrs->GetHolderEntry(); + } + + _PTR(SObject) aSObject = thePlane->getPlaneObject(); + _PTR(ChildIterator) aRefIter = myStudy->NewChildIterator(aSObject); + for (; aRefIter->More(); aRefIter->Next()) { + _PTR(SObject) aObj = aRefIter->Value(); + _PTR(SObject) aRefPrsObject; + if (aObj->ReferencedObject(aRefPrsObject)) { // If it is referenced on current plane + if (aRefPrsObject->GetID() == aPrsEntry) { + aPrs->AddClippingPlane(thePlane); + } + } + } + } + } + } + } + } +} + +//************************************************************* +long VISU_ClippingPlaneMgr::CreateClippingPlane(double X,double Y, double Z, + double dX, double dY, double dZ, + bool isAuto, const char* name) +{ + _PTR(SObject) aObjPtr = CreateClippingPlaneObject(X, Y, Z, dX, dY, dZ, isAuto, name); + return myPlanes->GetNumberOfItems() - 1; +} + + +//************************************************************* +_PTR(SObject) VISU_ClippingPlaneMgr::CreateClippingPlaneObject(double X,double Y, double Z, + double dX, double dY, double dZ, + bool isAuto, const char* name) +{ + _PTR(SObject) aPlaneObj; + if(!myStudy->GetProperties()->IsLocked()) { + _PTR(SObject) aFolder = GetClippingPlanesFolder(true); + if (aFolder) { + _PTR(StudyBuilder) aBuilder = myStudy->NewBuilder(); + aPlaneObj = aBuilder->NewObject(aFolder); + + // Save Name + _PTR(GenericAttribute) anAttr; + anAttr = aBuilder->FindOrCreateAttribute(aPlaneObj,"AttributeName"); + _PTR(AttributeName) aName(anAttr); + aName->SetValue(name); + + //Save Parameters + double aParams[6]; + aParams[0] = X; + aParams[1] = Y; + aParams[2] = Z; + aParams[3] = dX; + aParams[4] = dY; + aParams[5] = dZ; + + anAttr = aBuilder->FindOrCreateAttribute(aPlaneObj,"AttributeSequenceOfReal"); + _PTR(AttributeSequenceOfReal) aArray(anAttr); + if (aArray->Length() == 6) { + for (int i = 0; i < 6; i++) + aArray->ChangeValue(i+1, aParams[i]); + } else { + for (int i = 0; i < 6; i++) + aArray->Add(aParams[i]); + } + // Save Bool Flag + anAttr = aBuilder->FindOrCreateAttribute(aPlaneObj,"AttributeInteger"); + _PTR(AttributeInteger) aFlag(anAttr); + aFlag->SetValue(isAuto? 1 : 0); + + vtkSmartPointer aPlane = VISU_CutPlaneFunction::New(); + aPlane->Delete(); //vtkSmartPointer specific + aPlane->setPlaneObject(aPlaneObj); + aPlane->SetOrigin(X, Y, Z); + aPlane->SetNormal(dX, dY, dZ); + aPlane->setName(name); + aPlane->setAuto(isAuto); + applyPlaneToAll(aPlane); + myPlanes->AddItem(aPlane.GetPointer()); + } + } + return aPlaneObj; +} + + +//************************************************************* +void VISU_ClippingPlaneMgr::EditClippingPlane(long id, double X,double Y, double Z, + double dX, double dY, double dZ, + bool isAuto, const char* name) +{ + VISU_CutPlaneFunction* aPlane = GetClippingPlane(id); + if (aPlane != NULL) { + _PTR(SObject) aSObj = aPlane->getPlaneObject(); + aPlane->SetOrigin(X, Y, Z); + aPlane->SetNormal(dX, dY, dZ); + aPlane->setName(name); + aPlane->setAuto(isAuto); + + if(!myStudy->GetProperties()->IsLocked()) { + _PTR(GenericAttribute) anAttr; + if (aSObj->FindAttribute(anAttr, "AttributeSequenceOfReal")) { + _PTR(AttributeSequenceOfReal) aArray(anAttr); + aArray->ChangeValue(1, X); + aArray->ChangeValue(2, Y); + aArray->ChangeValue(3, Z); + aArray->ChangeValue(4, dX); + aArray->ChangeValue(5, dY); + aArray->ChangeValue(6, dZ); + } + if (aSObj->FindAttribute(anAttr, "AttributeInteger")) { + _PTR(AttributeInteger) aFlag(anAttr); + aFlag->SetValue(isAuto? 1 : 0); + } + if (aSObj->FindAttribute(anAttr, "AttributeName")) { + _PTR(AttributeName) aName(anAttr); + aName->SetValue(name); + } + // Remove references on presentations if it becomes Auto plane + _PTR(SObject) aPlaneSObj = aPlane->getPlaneObject(); + if (aPlane->isAuto()) { + _PTR(ChildIterator) aIter = myStudy->NewChildIterator(aPlaneSObj); + _PTR(StudyBuilder) aBuilder = myStudy->NewBuilder(); + for (; aIter->More(); aIter->Next()) { + _PTR(SObject) aObj = aIter->Value(); + aBuilder->RemoveObject(aObj); + } + } + } + } +} + + + +//************************************************************* + /* Returns clipping plane by its Id */ +VISU_CutPlaneFunction* VISU_ClippingPlaneMgr::GetClippingPlane(long id) +{ + if ((id < 0) || (id >= GetClippingPlanesNb())) + return NULL; + return (VISU_CutPlaneFunction*) myPlanes->GetItemAsObject(id); +} + +//************************************************************* + /* Deletes clipping plane by its Id */ +bool VISU_ClippingPlaneMgr::DeleteClippingPlane(long id) +{ + _PTR(SObject) aFolder = GetClippingPlanesFolder(false); + if (aFolder) { + VISU_CutPlaneFunction* aPlane = GetClippingPlane(id); + if (aPlane != NULL) { + _PTR(SComponent) aVisuSO = myStudy->FindComponent("VISU"); + _PTR(ChildIterator) aChildIter = myStudy->NewChildIterator(aVisuSO); + for (aChildIter->InitEx(true); aChildIter->More(); aChildIter->Next()) { + _PTR(SObject) aSObject = aChildIter->Value(); + CORBA::Object_var anObject = VISU::ClientSObjectToObject(aSObject); + if(VISU::Base_i* aBase = dynamic_cast(VISU::GetServant(anObject).in())) { + VISU::Prs3d_i* aPrs; + if(aBase->GetType() == VISU::TCOLOREDPRS3DHOLDER){ + CORBA::Object_var anObject = aBase->_this(); + VISU::ColoredPrs3dHolder_var aHolder = VISU::ColoredPrs3dHolder::_narrow(anObject); + VISU::Prs3d_var aPrs3d = aHolder->GetDevice(); + aPrs = dynamic_cast(VISU::GetServant(aPrs3d).in()); + } else + aPrs = dynamic_cast(aBase); + + if (aPrs) { + if (ContainsPlane(aPrs, aPlane)) { + short aTag1 = aPlane->getPlaneObject()->Tag(); + for (int j = aPrs->GetNumberOfClippingPlanes()-1; j > -1; j--) { + VISU_CutPlaneFunction* aPln = dynamic_cast + (aPrs->GetClippingPlane(j)); + if (aPln) { + short aTag2 = aPln->getPlaneObject()->Tag(); + if (aTag1 == aTag2) { + aPrs->RemoveClippingPlane(j); + break; + } + } + } + } + } + } + } + _PTR(SObject) aSObj = aPlane->getPlaneObject(); + if (aSObj) { + _PTR(StudyBuilder) aBuilder = myStudy->NewBuilder(); + aBuilder->RemoveObject(aSObj); + } + return true; + } + } + return false; +} + +//************************************************************* +bool VISU_ClippingPlaneMgr::ContainsPlane(VISU::Prs3d_ptr thePrs, VISU_CutPlaneFunction* thePlane) +{ + VISU::Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(thePrs).in()); + return ContainsPlane(aPrs, thePlane); +} + +//************************************************************* +bool VISU_ClippingPlaneMgr::ContainsPlane(VISU::Prs3d_i* thePrs, VISU_CutPlaneFunction* thePlane) +{ + VISU::Prs3d_i* aPrs = thePrs; + if (thePrs->GetType() == VISU::TCOLOREDPRS3DHOLDER) { + VISU::ColoredPrs3dHolder_i* aHolder = dynamic_cast(thePrs); + if (!aHolder) return false; + aPrs = aHolder->GetPrs3dDevice(); + } + string aEntry = thePlane->getPlaneObject()->GetID(); + for (int i = 0; i < thePrs->GetNumberOfClippingPlanes(); i++) { + VISU_CutPlaneFunction* aPlane = dynamic_cast(thePrs->GetClippingPlane(i)); + if (aPlane) { + if (aPlane->getPlaneObject()->GetID() == aEntry) { + return true; + } + } + } + return false; +} + + +//************************************************************* + /* Applyes a clipping plane with Id to presentation thePrs */ +bool VISU_ClippingPlaneMgr::ApplyClippingPlane(VISU::Prs3d_i* thePrs, long id) +{ + //VISU::Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(thePrs).in()); + if (!thePrs) return false; + + VISU_CutPlaneFunction* aPlane = GetClippingPlane(id); + if (!aPlane) return false; + if (!ContainsPlane(thePrs, aPlane)) { + thePrs->AddClippingPlane(aPlane); + if (!aPlane->isAuto()) { + string aEntry = thePrs->GetEntry(); + if (aEntry.length() == 0) { + VISU::ColoredPrs3d_i* aColPrs = dynamic_cast(thePrs); + if (aColPrs) + aEntry = aColPrs->GetHolderEntry(); + } + if(!myStudy->GetProperties()->IsLocked()) { + _PTR(StudyBuilder) aBuilder = myStudy->NewBuilder(); + _PTR(SObject) aPrsSObj = myStudy->FindObjectID(aEntry); + _PTR(SObject) aSObject = aPlane->getPlaneObject(); + _PTR(SObject) aNewObj = aBuilder->NewObject(aSObject); + aBuilder->Addreference(aNewObj, aPrsSObj); + } + } + return true; + } + return false; +} + +//************************************************************* +bool VISU_ClippingPlaneMgr::DetachClippingPlane(VISU::Prs3d_i* thePrs, long id) +{ + VISU_CutPlaneFunction* aPlane = GetClippingPlane(id); + //VISU::Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(thePrs).in()); + if (aPlane && thePrs) { + if (ContainsPlane(thePrs, aPlane)) { + bool isRemoved = false; + short aTag1 = aPlane->getPlaneObject()->Tag(); + for (int j = thePrs->GetNumberOfClippingPlanes()-1; j > -1; j--) { + VISU_CutPlaneFunction* aPln = dynamic_cast + (thePrs->GetClippingPlane(j)); + if (aPln) { + short aTag2 = aPln->getPlaneObject()->Tag(); + if (aTag1 == aTag2) { + thePrs->RemoveClippingPlane(j); + isRemoved = true; + break; + } + } + } + if(!myStudy->GetProperties()->IsLocked()) { + _PTR(SObject) aSObject = aPlane->getPlaneObject(); + _PTR(StudyBuilder) aBuilder = myStudy->NewBuilder(); + + string aEntry = thePrs->GetEntry(); + if (aEntry.length() == 0) { + VISU::ColoredPrs3d_i* aColPrs = dynamic_cast(thePrs); + if (aColPrs) + aEntry = aColPrs->GetHolderEntry(); + } + _PTR(ChildIterator) aIter = myStudy->NewChildIterator(aSObject); + for (; aIter->More(); aIter->Next()) { + _PTR(SObject) aRefObj = aIter->Value(); + if(aRefObj) { + _PTR(SObject) aRefPrsObject; + if (aRefObj->ReferencedObject(aRefPrsObject)) { + if (aRefPrsObject->GetID() == aEntry) { + aBuilder->RemoveObject(aRefObj); + break; + } + } + } + } + } + return isRemoved; + } + } + return false; +} + + +//************************************************************* + /* Get number of clipping planes */ +long VISU_ClippingPlaneMgr::GetClippingPlanesNb() +{ + return myPlanes->GetNumberOfItems(); +} + + +//************************************************************* +_PTR(SObject) VISU_ClippingPlaneMgr::GetClippingPlanesFolder(bool toCreate) +{ + _PTR(SObject) aFolder; + _PTR(SComponent) aVisuSO = myStudy->FindComponent("VISU"); + if (!aVisuSO) return aFolder; + + aFolder = myStudy->FindObject(CLIP_PLANES_FOLDER); + if (!aFolder && toCreate) { + _PTR(StudyBuilder) aBuilder = myStudy->NewBuilder(); + aFolder = aBuilder->NewObject(aVisuSO); + + _PTR(GenericAttribute) anAttr; + anAttr = aBuilder->FindOrCreateAttribute(aFolder,"AttributeName"); + _PTR(AttributeName) aName(anAttr); + aName->SetValue(CLIP_PLANES_FOLDER); + } + return aFolder; +} + + + + +//**************************************************************** +//**************************************************************** +//**************************************************************** +VISU_CutPlaneFunction* VISU_CutPlaneFunction::New() +{ + return new VISU_CutPlaneFunction(); +} + +void VISU_CutPlaneFunction::setActive(bool theActive) +{ + myIsActive = theActive; + Modified(); +} + +double VISU_CutPlaneFunction::EvaluateFunction(double x[3]) +{ + if (myIsActive) + return vtkPlane::EvaluateFunction(x); + else + return -1; +} + +double VISU_CutPlaneFunction::EvaluateFunction(double x, double y, double z) +{ + if (myIsActive) + return vtkPlane::EvaluateFunction(x,y,z); + else + return -1; +} + +VISU_CutPlaneFunction::VISU_CutPlaneFunction(): + myIsActive(true) +{ + +} + +VISU_CutPlaneFunction::~VISU_CutPlaneFunction() +{ +} + diff --git a/src/VISU_I/VISU_ClippingPlaneMgr.hxx b/src/VISU_I/VISU_ClippingPlaneMgr.hxx new file mode 100644 index 00000000..c71e3d98 --- /dev/null +++ b/src/VISU_I/VISU_ClippingPlaneMgr.hxx @@ -0,0 +1,129 @@ + +// VISU OBJECT : interactive object for VISU entities implementation +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// +// File : VISU_ClippingPlaneMgr.hxx +// Author : VSV +// Module : VISU + + +#ifndef _VISU_ClippingPlane_H_ +#define _VISU_ClippingPlane_H_ + +#include "VISU_I.hxx" +#include "VISUConfig.hh" +#include "SALOME_Component_i.hxx" +#include "VISU_ColoredPrs3d_i.hh" + +#include +#include + +class vtkImplicitFunctionCollection; + + +class VISU_CutPlaneFunction: public vtkPlane +{ +public: + static VISU_CutPlaneFunction* New(); + + vtkTypeMacro(VISU_CutPlaneFunction, vtkPlane); + + virtual double EvaluateFunction(double x[3]); + virtual double EvaluateFunction(double x, double y, double z); + + void setActive(bool theActive); + bool isActive() const { return myIsActive; } + + void setPlaneObject(_PTR(SObject) aSOPlane) { mySObject = aSOPlane; } + _PTR(SObject) getPlaneObject() const { return mySObject; } + + void setName(string theName) { myName = theName; } + string getName() const { return myName; } + + void setAuto(bool isAuto) { myIsAuto = isAuto; } + bool isAuto() const { return myIsAuto; } + +protected: + VISU_CutPlaneFunction(); + ~VISU_CutPlaneFunction(); + +private: + bool myIsActive; + _PTR(SObject) mySObject; + string myName; + bool myIsAuto; +}; + + + +class VISU_ClippingPlaneMgr { +public: + VISU_ClippingPlaneMgr(); + ~VISU_ClippingPlaneMgr(); + + void SetStudy(_PTR(Study) theStudy); + + + long CreateClippingPlane(double X,double Y, double Z, + double dX, double dY, double dZ, + bool isAuto, const char* name); + + void EditClippingPlane(long id, double X,double Y, double Z, + double dX, double dY, double dZ, + bool isAuto, const char* name); + + _PTR(SObject) CreateClippingPlaneObject(double X,double Y, double Z, + double dX, double dY, double dZ, + bool isAuto, const char* name); + + /* Returns clipping plane by its Id */ + VISU_CutPlaneFunction* GetClippingPlane(long id); + + /* Deletes clipping plane by its Id */ + bool DeleteClippingPlane(long id); + + /* Applyes a clipping plane with Id to presentation thePrs */ + bool ApplyClippingPlane(VISU::Prs3d_i* thePrs, long id); + + bool DetachClippingPlane(VISU::Prs3d_i* thePrs, long id); + + /* Get number of clipping planes */ + long GetClippingPlanesNb(); + + _PTR(SObject) GetClippingPlanesFolder(bool toCreate); + + static bool ContainsPlane(VISU::Prs3d_ptr thePrs, VISU_CutPlaneFunction* thePlane); + static bool ContainsPlane(VISU::Prs3d_i* thePrs, VISU_CutPlaneFunction* thePlane); + + vtkImplicitFunctionCollection* GetPlanesList() const { return myPlanes; } + + +private: + void applyPlaneToAll(VISU_CutPlaneFunction* thePlane); + + + _PTR(Study) myStudy; + + vtkImplicitFunctionCollection* myPlanes; +}; + +#endif diff --git a/src/VISU_I/VISU_Gen_i.cc b/src/VISU_I/VISU_Gen_i.cc index 242001aa..22cda262 100644 --- a/src/VISU_I/VISU_Gen_i.cc +++ b/src/VISU_I/VISU_Gen_i.cc @@ -257,6 +257,7 @@ namespace VISU CORBA::String_var aStudyName = aListOfOpenStudies[0]; //aFileInfo.setFile(aStudyName.in()); myStudyDocument = aStudyManager->GetStudyByName(aStudyName/*aFileInfo.baseName()*/); + myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument)); }else if(MYDEBUG) MESSAGE("VISU_Gen_i::VISU_Gen_i : there is no opened study in StudyManager !!!"); } @@ -537,6 +538,7 @@ namespace VISU std::string aStudyName (aName.in()); if(MYDEBUG) MESSAGE("StudyId = " << theStudy->StudyId() << "; Name = '" << aName.in() << "'"); myStudyDocument = SALOMEDS::Study::_duplicate(theStudy); + myClippingPlaneMgr.SetStudy(GetStudy(myStudyDocument)); ProcessVoidEvent(new TEvent(aStudyName)); @@ -1374,4 +1376,74 @@ namespace VISU { return ColoredPrs3dCache_i::GetInstance(theStudy); } + + + CORBA::Long VISU_Gen_i::CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name) + { + return myClippingPlaneMgr.CreateClippingPlane(X, Y, Z, dX, dY, dZ, isAuto, name); + } + + + void VISU_Gen_i::EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name) + { + myClippingPlaneMgr.EditClippingPlane(id, X, Y, Z, dX, dY, dZ, isAuto, name); + } + + /* Returns clipping plane by its Id */ + VISU::ClippingPlane* VISU_Gen_i::GetClippingPlane(CORBA::Long id) + { + VISU_CutPlaneFunction* aPlane = myClippingPlaneMgr.GetClippingPlane(id); + + if (aPlane != NULL) { + double aOrigin[3]; + double aDir[3]; + aPlane->GetOrigin(aOrigin); + aPlane->GetNormal(aDir); + + VISU::ClippingPlane* aRetPlane = new VISU::ClippingPlane; + aRetPlane->X = aOrigin[0]; + aRetPlane->Y = aOrigin[1]; + aRetPlane->Z = aOrigin[2]; + aRetPlane->dX = aDir[0]; + aRetPlane->dY = aDir[1]; + aRetPlane->dZ = aDir[2]; + aRetPlane->isAuto = aPlane->isAuto(); + + aRetPlane->name = aPlane->getName().c_str(); + return aRetPlane; + } + return NULL; + } + + /* Deletes clipping plane by its Id */ + CORBA::Boolean VISU_Gen_i::DeleteClippingPlane(CORBA::Long id) + { + return myClippingPlaneMgr.DeleteClippingPlane(id); + } + + /* Applyes a clipping plane with Id to presentation thePrs */ + CORBA::Boolean VISU_Gen_i::ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id) + { + VISU::Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(thePrs).in()); + return myClippingPlaneMgr.ApplyClippingPlane(aPrs, id); + } + + /* Detaches a clipping plane with Id from presentation thePrs */ + CORBA::Boolean VISU_Gen_i::DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id) + { + VISU::Prs3d_i* aPrs = dynamic_cast(VISU::GetServant(thePrs).in()); + return myClippingPlaneMgr.DetachClippingPlane(aPrs, id); + } + + /* Get number of clipping planes */ + CORBA::Long VISU_Gen_i::GetClippingPlanesNb() + { + return myClippingPlaneMgr.GetClippingPlanesNb(); + } + + } diff --git a/src/VISU_I/VISU_Gen_i.hh b/src/VISU_I/VISU_Gen_i.hh index 1f38e06e..612b048c 100644 --- a/src/VISU_I/VISU_Gen_i.hh +++ b/src/VISU_I/VISU_Gen_i.hh @@ -30,6 +30,7 @@ #include "SALOME_Component_i.hxx" #include "SALOME_NamingService.hxx" #include "VISU_ColoredPrs3d_i.hh" +#include "VISU_ClippingPlaneMgr.hxx" #include @@ -41,6 +42,8 @@ namespace VISU public virtual Base_i { SALOMEDS::Study_var myStudyDocument; + VISU_ClippingPlaneMgr myClippingPlaneMgr; + VISU_Gen_i(const VISU::VISU_Gen_i &); public: VISU_Gen_i(CORBA::ORB_ptr theORB, @@ -351,6 +354,33 @@ namespace VISU virtual VISU::ColoredPrs3dCache_ptr GetColoredPrs3dCache(SALOMEDS::Study_ptr theStudy); + + + virtual CORBA::Long CreateClippingPlane(CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name); + + virtual void EditClippingPlane(CORBA::Long id, CORBA::Double X,CORBA::Double Y, CORBA::Double Z, + CORBA::Double dX, CORBA::Double dY, CORBA::Double dZ, + CORBA::Boolean isAuto, const char* name); + + /* Returns clipping plane by its Id */ + virtual VISU::ClippingPlane* GetClippingPlane(CORBA::Long id); + + /* Deletes clipping plane by its Id */ + virtual CORBA::Boolean DeleteClippingPlane(CORBA::Long id); + + /* Applyes a clipping plane with Id to presentation thePrs */ + virtual CORBA::Boolean ApplyClippingPlane(Prs3d_ptr thePrs, CORBA::Long id); + + /* Detaches a clipping plane with Id from presentation thePrs */ + virtual CORBA::Boolean DetachClippingPlane(Prs3d_ptr thePrs, CORBA::Long id); + + /* Get number of clipping planes */ + virtual CORBA::Long GetClippingPlanesNb(); + + VISU_ClippingPlaneMgr& GetClippingPlaneMgr() { return myClippingPlaneMgr; } + }; }