X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FDisplayGUI%2FDisplayGUI.cxx;h=e35c95e41b434e9067acf8bf24e31139ee183b46;hb=6c057505a6e4bcff162cfb8b86deeda0eefff60a;hp=73235ed1b2638f44061cac6da7de74c624048df7;hpb=8bc9b430c5f9f3cf77539fee550f1b56769d3893;p=modules%2Fgeom.git diff --git a/src/DisplayGUI/DisplayGUI.cxx b/src/DisplayGUI/DisplayGUI.cxx index 73235ed1b..e35c95e41 100644 --- a/src/DisplayGUI/DisplayGUI.cxx +++ b/src/DisplayGUI/DisplayGUI.cxx @@ -1,59 +1,70 @@ -// GEOM GEOMGUI : GUI for Geometry component +// GEOM GEOMGUI : GUI for Geometry component // -// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// 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 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. +// 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 +// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// File : DisplayGUI.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) // -// -// File : DisplayGUI.cxx -// Author : Damien COQUERET -// Module : GEOM -// $Header: -using namespace std; #include "DisplayGUI.h" +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include -#include "QAD_RightFrame.h" -#include "GEOM_AssemblyBuilder.h" -#include "VTKViewer_ViewFrame.h" -#include "OCCViewer_ViewFrame.h" -#include "OCCViewer_Viewer3d.h" -#include "SALOMEGUI_ImportOperation.h" -#include "SALOME_ListIteratorOfListIO.hxx" +#include + +#include +#include +#include #include +#include + //======================================================================= -// function : DisplayGUI() +// function : DisplayGUI::DisplayGUI() // purpose : Constructor //======================================================================= -DisplayGUI::DisplayGUI() : - QObject() +DisplayGUI::DisplayGUI( GeometryGUI* parent ) : GEOMGUI( parent ) { - myGeomBase = new GEOMBase(); - myGeomGUI = GEOMContext::GetGeomGUI(); - myGeom = myGeomGUI->myComponentGeom; } - //======================================================================= -// function : ~DisplayGUI() +// function : DisplayGUI::~DisplayGUI() // purpose : Destructor //======================================================================= DisplayGUI::~DisplayGUI() @@ -62,947 +73,410 @@ DisplayGUI::~DisplayGUI() //======================================================================= -// function : OnGUIEvent() -// purpose : +// function : DisplayGUI::OnGUIEvent() +// purpose : Dispatch menu command //======================================================================= -bool DisplayGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent) +bool DisplayGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent) { - DisplayGUI* myDisplayGUI = new DisplayGUI(); + SalomeApp_Application* app = getGeometryGUI()->getApp(); + if (!app) return false; - switch (theCommandID) - { - case 211: // MENU VIEW - WIREFRAME/SHADING - { - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - QApplication::setOverrideCursor(waitCursor); - - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - int themode = myRenderInter->GetDisplayMode(); - if(themode==0) { - myRenderInter->SetDisplayMode(1); - QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME")); - } - else { - myRenderInter->SetDisplayMode(0); - QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING")); - } + LightApp_SelectionMgr *Sel = app->selectionMgr(); + SALOME_ListIO selected; + Sel->selectedObjects( selected ); - QApplication::restoreOverrideCursor(); - } - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - QApplication::setOverrideCursor(Qt::waitCursor); - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode(); - AIS_DisplayMode newmode = (mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - List.Append(List1); - - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - ic->SetDisplayMode(aSh,Standard_Integer(newmode),true); - } - ite.Next(); - } - - ic->SetDisplayMode(newmode, Standard_False); - if(newmode == 1) - QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME")); - else - QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING")); - - QApplication::restoreOverrideCursor(); - } - break; - } - case 212: // MENU VIEW - DISPLAY ALL - { - myDisplayGUI->OnDisplayAll(); - break; - } - case 213: // MENU VIEW - DISPLAY ONLY - { - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) - myDisplayGUI->OnVTKDisplayOnly(); - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) - myDisplayGUI->OnDisplayOnly(); - break; - } - case 214: // MENU VIEW - ERASE ALL - { - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) - ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->EraseAll(); - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - - ic->EraseAll(Standard_True, Standard_False); - ic->Display(v3d->getTrihedron()); - } - break; - } - case 215: // MENU VIEW - ERASE ONLY - { - myDisplayGUI->OnErase(); - break; - } - case 8031: // POPUP VIEWER - WIREFRAME/SHADING - { - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - // VTK - VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - - QApplication::setOverrideCursor(Qt::waitCursor); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IOS = It.Value(); - myRenderInter->SwitchRepresentation(IOS, false); - } - myRenderInter->Render(); - QApplication::restoreOverrideCursor(); - } - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - QApplication::setOverrideCursor(Qt::waitCursor); - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - Handle(GEOM_AISShape) Shape = myDisplayGUI->myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true); - if(!Shape.IsNull()) { - AIS_DisplayMode mode = (AIS_DisplayMode)Shape->DisplayMode(); - if(mode == -1) - mode = (AIS_DisplayMode)ic->DisplayMode(); - - ic->SetDisplayMode(Shape, mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame, false); - } - } - ic->UpdateCurrentViewer(); - } - QApplication::restoreOverrideCursor(); - break; - } - default: - { - parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); - break; - } + switch (theCommandID) { + case 211: // MENU VIEW - WIREFRAME/SHADING + { + InvertDisplayMode(); + int newMode = GetDisplayMode(); + getGeometryGUI()->action( 211 )->setText + ( newMode == 1 ? tr( "GEOM_MEN_WIREFRAME" ) : tr("GEOM_MEN_SHADING") ); + getGeometryGUI()->menuMgr()->update(); + break; + } + case 212: // MENU VIEW - DISPLAY ALL + { + getGeometryGUI()->EmitSignalDeactivateDialog(); + DisplayAll(); + break; + } + case 213: // MENU VIEW - DISPLAY ONLY + { + getGeometryGUI()->EmitSignalDeactivateDialog(); + DisplayOnly(); + break; + } + case 214: // MENU VIEW - ERASE ALL + { + EraseAll(); + break; + } + case 215: // MENU VIEW - ERASE + { + Erase(); + break; + } + case 216: // MENU VIEW - DISPLAY + { + getGeometryGUI()->EmitSignalDeactivateDialog(); + Display(); + break; } + case 80311: // POPUP VIEWER - WIREFRAME + { + ChangeDisplayMode( 0 ); + break; + } + case 80312: // POPUP VIEWER - SHADING + { + ChangeDisplayMode( 1 ); + break; + } + default: + { + app->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID)); + break; + } + } + Sel->setSelectedObjects( selected ); return true; } - -//================================================================================= -// function : BuildPresentation() -// purpose : static -//================================================================================= -void DisplayGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO) +//===================================================================================== +// function : DisplayGUI::DisplayAll() +// purpose : Display all GEOM objects +//===================================================================================== +void DisplayGUI::DisplayAll() { - DisplayGUI* myDisplayGUI = new DisplayGUI(); - - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - - OCCViewer_Viewer3d* v3d; - Handle(AIS_InteractiveContext) ic; - vtkRenderer* Renderer; - - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - ic = v3d->getAISContext(); - } - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - } - else + SalomeApp_Application* app = getGeometryGUI()->getApp(); + if ( !app ) return; + + SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); + if ( !appStudy ) return; + _PTR(Study) aStudy = appStudy->studyDS(); + if ( !aStudy ) return; + _PTR(SComponent) SC ( aStudy->FindComponent( "GEOM" ) ); + if ( !SC ) return; - if(theIO.IsNull()) - MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed") + SALOME_ListIO listIO; + _PTR(ChildIterator) anIter ( aStudy->NewChildIterator( SC ) ); + anIter->InitEx( true ); - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - // VTK - - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry()); - - SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry()); + SUIT_OverrideCursor(); - VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - if(myRenderInter->isInViewer(theIO)) { - myRenderInter->Display(theIO, false); - } - else { - // Create new actor - if(!obj->_is_nil()) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - - bool useSubItems = false; - SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj); - if(myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) { - while (anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - if (!myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } - else - anIter->Next(); - } - else - anIter->Next(); - } - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myDisplayGUI->myGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = myDisplayGUI->myGeomGUI->GetShapeReader().GetShape(myDisplayGUI->myGeom,aShape); - - if(obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theAllActors = theRenderer->GetActors(); - theAllActors->InitTraversal(); - vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); - Handle(SALOME_InteractiveObject) anIObj; - // don't create new study object if it already exists - bool isDisplayed = false; - while(!(actor==NULL)) { - SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); - if(Gactor!=NULL) { - if(Gactor->hasIO()) { - if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { - isDisplayed = true; - anIObj = Gactor->getIO(); - if(!anIObj.IsNull()) myRenderInter->Display(anIObj, false); - } - } - } - actor=(vtkActor*)(theAllActors->GetNextActor()); - } - if(!isDisplayed) { - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() ); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - - vtkRenderWindow *renWin = theRenderer->GetRenderWindow(); - int themode = myRenderInter->GetDisplayMode(); - - vtkActorCollection* theActors = - GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myDisplayGUI->myGeomGUI->GetFatherior(),"GEOM"); - IO->setEntry(obj->GetID()); - GActor->setIO(IO); - GActor->setName(theIO->getName()); - - theRenderer->AddActor(GActor); - // renWin->Render(); - anActor = (vtkActor*)theActors->GetNextActor(); - } - } - } - // next item iteration - if(useSubItems) { - anIter->Next(); - anAttr = SALOMEDS::GenericAttribute::_nil(); - while(anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } - else - anIter->Next(); - } - } - else - anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - // No viewer update should be done here! - //myRenderInter->Render(); - //QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser( true ); - } - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - if(v3d->isInViewer(theIO, true)) { - Standard_Boolean found; - Handle(GEOM_AISShape) aSh = myDisplayGUI->myGeomBase->ConvertIOinGEOMAISShape(theIO, found, true); - if(found) { - ic->Display(aSh, false); - ic->AddOrRemoveCurrentObject(aSh, false); - } - + while( anIter->More() ) { + _PTR(SObject) valSO ( anIter->Value() ); + _PTR(SObject) refSO; + if ( !valSO->ReferencedObject( refSO ) ) { + listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(), + SC->ComponentDataType().c_str(), + valSO->GetName().c_str()) ); } - else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry()); - if(!obj->_is_nil()) { - MESSAGE("BuildPresentation(): SObject not null") - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - MESSAGE("BuildPresentation(): SObject has IOR") - // this SObject may be GEOM module root SObject - - bool useSubItems = false; - SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj); - if(myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) { - while(anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - if(!myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } - else - anIter->Next(); - } - else - anIter->Next(); - } - } + anIter->Next(); + } + GEOM_Displayer( appStudy ).Display( listIO, true ); +} - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myDisplayGUI->myGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = myDisplayGUI->myGeomGUI->GetShapeReader().GetShape(myDisplayGUI->myGeom,aShape); - if(Shape.IsNull()) - MESSAGE("BuildPresentation(): TopoDS_Shape is null!") - if(obj->FindAttribute(anAttr, "AttributeName")) { - MESSAGE("BuildPresentation(): SObject has Name") - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // searchin for already displayed objects with the same shape - AIS_ListOfInteractive aDisplayed; - ic->DisplayedObjects(aDisplayed); - AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); - Handle(AIS_Shape) anAISShape; - for(;anIObjects.More();anIObjects.Next()) { - anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); - if(!anAISShape.IsNull()) { - if(anAISShape->Shape().IsSame(Shape)) - break; - anAISShape.Nullify(); - } - } - if(!anAISShape.IsNull()) { - if(!ic->IsDisplayed(anAISShape)) - ic->Display(anAISShape, false); - } - else { - if(!useSubItems) { - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() ); - op->start(); - if (fatherSF->_is_nil()) - MESSAGE("BuildPresentation(): fatherSF is nil!") - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - } - Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value()); - aSh->SetShadingColor(myDisplayGUI->myGeomBase->myShadingColor); - aSh->SetInfiniteState(Shape.Infinite()); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myDisplayGUI->myGeomGUI->GetFatherior(), "GEOM"); - IO->setEntry(obj->GetID()); - aSh->setIO(IO); - aSh->setName(aName->Value()); - ic->Display(aSh, false); - if(!useSubItems) - ic->AddOrRemoveCurrentObject(aSh, false); - } - } - // next item iteration - if(useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while (anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } - else - anIter->Next(); - } - } - else - anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } +//===================================================================================== +// function : DisplayGUI::EraseAll() +// purpose : Erase all GEOM objects +//===================================================================================== +void DisplayGUI::EraseAll() +{ + SUIT_OverrideCursor(); + + SUIT_Application* app = getGeometryGUI()->getApp(); + if ( app ) { + SUIT_ViewWindow* vw = app->desktop()->activeWindow(); + if ( vw ) { + SalomeApp_Study* appStudy = dynamic_cast( app->activeStudy() ); + SUIT_ViewManager* vman = vw->getViewManager(); + if ( vman->getType() == OCCViewer_Viewer::Type() || + vman->getType() == SVTK_Viewer::Type() ) { + GEOM_Displayer( appStudy ).EraseAll(); } } - // No viewer update should be done here! - //QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser( true ); - //ic->UpdateCurrentViewer(); } } +//===================================================================================== +// function : DisplayGUI::DisplayOnly() +// purpose : Display selected GEOM objects and erase other +//===================================================================================== +void DisplayGUI::DisplayOnly() +{ + EraseAll(); + Display(); +} //===================================================================================== -// function : OnDisplayAll() -// purpose : +// function : DisplayGUI::Display() +// purpose : Display selected GEOM objects //===================================================================================== -void DisplayGUI::OnDisplayAll(bool onlyPreviousDisplayedObject) +void DisplayGUI::Display() { - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) myContext = v3d->getAISContext(); - - //myContext->Display(v3d->getTrihedron()); - - if(!onlyPreviousDisplayedObject) { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM"); - SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SC); - for(; it->More();it->Next()) { - SALOMEDS::SObject_var CSO = it->Value(); - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::GenericAttribute_var anAttr; - if(CSO->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - Standard_Boolean testResult; - Handle(GEOM_AISShape) aSh = myGeomBase->ConvertIORinGEOMAISShape(anIOR->Value(), testResult); - if(testResult) - myContext->Display(aSh); - else { - GEOM::GEOM_Shape_ptr aShape = myGeom->GetIORFromString(anIOR->Value()); - bool AddInSt = myGeomBase->mySettings_AddInStudy; - myGeomBase->mySettings_AddInStudy = false; - myGeomBase->Display(aShape); - myGeomBase->mySettings_AddInStudy = AddInSt; + SALOME_ListIO listIO; + + SalomeApp_Application* app = getGeometryGUI()->getApp(); + if ( !app ) return; + + SalomeApp_Study* anActiveStudy = dynamic_cast( app->activeStudy() ); + if ( !anActiveStudy ) return; + + //get SalomeApp selection manager + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + if ( !aSelMgr ) return; + + SALOME_ListIO aList; + aSelMgr->selectedObjects( aList ); + SALOME_ListIteratorOfListIO It( aList ); + + SUIT_OverrideCursor(); + + for( ;It.More();It.Next() ) { + Handle(SALOME_InteractiveObject) anIObject = It.Value(); + if ( anIObject->hasEntry() ) { + _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) ); + if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) { + _PTR(SComponent) SC ( SO->GetFatherComponent() ); + // if component is selected + listIO.Clear(); + _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) ); + anIter->InitEx( true ); + while( anIter->More() ) { + _PTR(SObject) valSO ( anIter->Value() ); + _PTR(SObject) refSO; + if ( !valSO->ReferencedObject( refSO ) ) { + listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(), + SC->ComponentDataType().c_str(), + valSO->GetName().c_str()) ); } + anIter->Next(); } + break; } - } - else { - AIS_ListOfInteractive aListDisplayedObject; - myContext->DisplayedObjects(aListDisplayedObject); - AIS_ListIteratorOfListOfInteractive ite(aListDisplayedObject); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if (aSh->hasIO()) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if (v3d->isInViewer(GIO,true)) - myContext->Display(aSh); - } - } - ite.Next(); + else { + listIO.Append( anIObject ); } } - } - else if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM"); - SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SC); - for(; it->More();it->Next()) { - SALOMEDS::SObject_var CSO = it->Value(); - SALOMEDS::AttributeIOR_var anIOR; - SALOMEDS::GenericAttribute_var anAttr; - if(CSO->FindAttribute(anAttr, "AttributeIOR")) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - Standard_Boolean testResult; - GEOM_Actor* aSh = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), testResult); - if(testResult) { - Handle(SALOME_InteractiveObject) IObject = aSh->getIO(); - ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->Display(IObject); - } - else { - GEOM::GEOM_Shape_ptr aShape = myGeom->GetIORFromString(anIOR->Value()); - bool AddInSt = myGeomBase->mySettings_AddInStudy; - myGeomBase->mySettings_AddInStudy = false; - myGeomBase->Display(aShape); - myGeomBase->mySettings_AddInStudy = AddInSt; - } - } + else { + listIO.Append( anIObject ); } } - return; + GEOM_Displayer( anActiveStudy ).Display( listIO, true ); } //===================================================================================== -// function : OnVTKDisplayOnly() -// purpose : +// function : DisplayGUI::Erase() +// purpose : Erase selected GEOM objects //===================================================================================== -void DisplayGUI::OnVTKDisplayOnly() +void DisplayGUI::Erase() { - QApplication::setOverrideCursor(Qt::waitCursor); - - // Erase all not selected actors - vtkRenderer* aren = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theActors = aren->GetActors(); - theActors->InitTraversal(); - vtkActor *ac = theActors->GetNextActor(); - while(!(ac==NULL)) { - if(ac->IsA("SALOME_Actor")) { - SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac); - if(!anActor->isHighlighted()) - anActor->VisibilityOff(); - } - ac = theActors->GetNextActor(); - } - - // Display selection - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() ); - - VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - if(myRenderInter->isInViewer(IObject)) { - myRenderInter->Display(IObject); - } - else { - // Create new actor - if(!obj->_is_nil()) { - if(!obj->FindAttribute(anAttr, "AttributeIOR")) - break; - // If selected object contains displayable subobjects, then do nothing - SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj); - SALOMEDS::GenericAttribute_var aTmpAttr; - - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value()); - if(CORBA::is_nil(aShape)) continue; - TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape); - - if(obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy()); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - int themode = myRenderInter->GetDisplayMode(); - vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(Shape, 0, themode, Standard_True); - theActors->InitTraversal(); - vtkActor* anActor = (vtkActor*)theActors->GetNextActor(); - while(!(anActor==NULL)) { - GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor); - GActor->setIO(IObject); - GActor->setName(IObject->getName()); - - theRenderer->AddActor(GActor); - vtkRenderWindow *renWin = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->GetRenderWindow(); - renWin->Render(); - anActor = (vtkActor*)theActors->GetNextActor(); + SALOME_ListIO listIO; + + SalomeApp_Application* app = getGeometryGUI()->getApp(); + if ( !app ) return; + + SalomeApp_Study* anActiveStudy = dynamic_cast( app->activeStudy() ); + if ( !anActiveStudy ) return; + + //get SalomeApp selection manager + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + if ( !aSelMgr ) return; + + SALOME_ListIO aList; + aSelMgr->selectedObjects( aList ); + SALOME_ListIteratorOfListIO It( aList ); + + SUIT_OverrideCursor(); + + for( ; It.More(); It.Next() ) { + Handle(SALOME_InteractiveObject) anIObject = It.Value(); + if ( anIObject->hasEntry() ) { + _PTR(SObject) SO ( anActiveStudy->studyDS()->FindObjectID( anIObject->getEntry() ) ); + if ( SO && QString(SO->GetID().c_str()) == QString(SO->GetFatherComponent()->GetID().c_str()) ) { + _PTR(SComponent) SC ( SO->GetFatherComponent() ); + // if component is selected + listIO.Clear(); + _PTR(ChildIterator) anIter ( anActiveStudy->studyDS()->NewChildIterator( SO ) ); + anIter->InitEx( true ); + while( anIter->More() ) { + _PTR(SObject) valSO ( anIter->Value() ); + _PTR(SObject) refSO; + if ( !valSO->ReferencedObject( refSO ) ) { + listIO.Append( new SALOME_InteractiveObject(valSO->GetID().c_str(), + SC->ComponentDataType().c_str(), + valSO->GetName().c_str()) ); } + anIter->Next(); } + break; + } + else { + listIO.Append( anIObject ); } } + else { + listIO.Append( anIObject ); + } } - QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(true); - QApplication::restoreOverrideCursor(); - return; -} + SUIT_ViewWindow* viewWindow = app->desktop()->activeWindow(); + bool aIsForced = true; + if(viewWindow->getViewManager()->getType() == SVTK_Viewer::Type()) + aIsForced = false; + GEOM_Displayer(anActiveStudy).Erase( listIO, aIsForced); + getGeometryGUI()->getApp()->selectionMgr()->clearSelected(); +} //===================================================================================== -// function : OnDisplayOnly() -// purpose : +// function : DisplayGUI::SetDisplayMode() +// purpose : Set display mode for the viewer (current viewer if - 0 ) //===================================================================================== -void DisplayGUI::OnDisplayOnly() +void DisplayGUI::SetDisplayMode( const int mode, SUIT_ViewWindow* viewWindow ) { - if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return; + SUIT_OverrideCursor(); - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - AIS_ListOfInteractive List; - ic->DisplayedObjects(List); - AIS_ListIteratorOfListOfInteractive ite(List); - while(ite.More()) { - if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value()); - if (!ic->IsSelected( aSh )) { - ic->Erase(aSh, Standard_True, Standard_True); + if ( !viewWindow ) + viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow(); + if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) { + SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView(); + aView->SetDisplayMode( mode ); + } + else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); + AIS_DisplayMode newmode = (mode == 1 ? AIS_Shaded : AIS_WireFrame); + AIS_ListOfInteractive List; + ic->DisplayedObjects( List ); + AIS_ListOfInteractive List1; + ic->ObjectsInCollector( List1 ); + List.Append( List1 ); + + AIS_ListIteratorOfListOfInteractive ite( List ); + while( ite.More() ) { + if( ite.Value()->IsInstance( STANDARD_TYPE(GEOM_AISShape) ) ) { + Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast( ite.Value() ); + ic->SetDisplayMode( aSh, Standard_Integer( newmode ),true ); } + ite.Next(); } - ite.Next(); - } - SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - - SALOME_ListIteratorOfListIO It1(Sel->StoredIObjects()); - for(;It1.More();It1.Next()) { - Handle(SALOME_InteractiveObject) IObject = It1.Value(); - - SALOMEDS::SObject_var fatherSF = - aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry()); - if(v3d->isInViewer(IObject, true)) { - AIS_ListOfInteractive List1; - ic->ObjectsInCollector(List1); - AIS_ListIteratorOfListOfInteractive ite1(List1); - while(ite1.More()) { - if(ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) { - Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value()); - if (aSh->hasIO()) { - Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO()); - if (IObject->isSame(GIO)) { - ic->Display(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - break; - } - } - } - ite1.Next(); - } - } - else { - if (IObject->hasEntry()) { - SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeName_var aName; - SALOMEDS::AttributeIOR_var anIOR; - if (!obj->_is_nil()) { - if (obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value()); - if(CORBA::is_nil(aShape)) continue; - TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape); - - if(obj->FindAttribute(anAttr, "AttributeName")) { - aName = SALOMEDS::AttributeName::_narrow(anAttr); - // open transaction - QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy()); - op->start(); - - SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF); - aStudyBuilder->Addreference(newObj1, obj); - // commit transaction - op->finish(); - } - - Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value()); - Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myGeomGUI->GetFatherior(),"GEOM"); - - IO->setEntry(obj->GetID()); - aSh->setIO(IO); - aSh->setName(aName->Value()); - ic->Display(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - } - } - } - } + ic->SetDisplayMode( newmode, Standard_False ); } } - //===================================================================================== -// function : OnErase() -// purpose : +// function : DisplayGUI::GetDisplayMode() +// purpose : Get display mode of the viewer (current viewer if - 0 ) //===================================================================================== -void DisplayGUI::OnErase() +int DisplayGUI::GetDisplayMode( SUIT_ViewWindow* viewWindow ) { - SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument(); - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) { - // VTK - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor(); - - if(myRenderInter->isInViewer(anIObject)) { - myRenderInter->Erase(anIObject); - } - else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if(!obj->_is_nil()) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while(anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } - else - anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape); - if(obj->FindAttribute(anAttr, "AttributeName")) { - // searchin for already displayed objects with the same shape - vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer(); - vtkActorCollection* theAllActors = theRenderer->GetActors(); - theAllActors->InitTraversal(); - vtkActor* actor = (vtkActor*)theAllActors->GetNextActor(); - Handle(SALOME_InteractiveObject) anIObj; - // don't create new study object if it already exists - bool isDisplayed = false; - while(!(actor==NULL)) { - SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor); - if(Gactor!=NULL) { - if(Gactor->hasIO()) { - if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) { - isDisplayed = true; - anIObj = Gactor->getIO(); - if(!anIObj.IsNull()) - myRenderInter->Erase(anIObj); - } - } - } - actor=(vtkActor*)(theAllActors->GetNextActor()); - } - } - if(useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while(anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } - else - anIter->Next(); - } - } - else - anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } - } - else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) { - // OCC - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - Handle(SALOME_InteractiveObject) anIObject; - for(;It.More();It.Next()) { - anIObject = It.Value(); - if(v3d->isInViewer(anIObject, true)) { - Standard_Boolean found; - Handle(GEOM_AISShape) aSh = myGeomBase->ConvertIOinGEOMAISShape(anIObject, found, true); - if(found) { - ic->Erase(aSh); - ic->AddOrRemoveCurrentObject(aSh, true); - } - } - else { - SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry()); - SALOMEDS::GenericAttribute_var anAttr; - SALOMEDS::AttributeIOR_var anIOR; - if(!obj->_is_nil()) { - if(obj->FindAttribute(anAttr, "AttributeIOR")) { - // this SObject may be GEOM module root SObject - SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj); - bool useSubItems = false; - while(anIter->More() && !useSubItems) { - SALOMEDS::SObject_var subobj = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttr; - if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) { - anAttr = aTmpAttr; - obj = subobj; - useSubItems = true; - } - else - anIter->Next(); - } - - while(useSubItems?anIter->More():!anAttr->_is_nil()) { - anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value()); - TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape); - if(obj->FindAttribute(anAttr, "AttributeName")) { - // searchin for already displayed objects with the same shape - AIS_ListOfInteractive aDisplayed; - ic->DisplayedObjects(aDisplayed); - AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed); - Handle(AIS_Shape) anAISShape; - for(;anIObjects.More();anIObjects.Next()) { - anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value()); - if(!anAISShape.IsNull()) { - if(anAISShape->Shape().IsSame(Shape)) - break; - anAISShape.Nullify(); - } - } - if(!anAISShape.IsNull()) { - if(ic->IsDisplayed(anAISShape)) - ic->Erase(anAISShape); - } - } - if(useSubItems) { - anIter->Next(); - anAttr=SALOMEDS::GenericAttribute::_nil(); - while(anIter->More() && anAttr->_is_nil()) { - SALOMEDS::SObject_var subobject = anIter->Value(); - SALOMEDS::GenericAttribute_var aTmpAttribute; - if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) { - anAttr = aTmpAttribute; - obj = subobject; - } - else - anIter->Next(); - } - } - else - anAttr = SALOMEDS::GenericAttribute::_nil(); - } - } - } - } - } + int dispMode = 0; + if ( !viewWindow ) + viewWindow = getGeometryGUI()->getApp()->desktop()->activeWindow(); + if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) { + SVTK_View* aView = ((SVTK_ViewWindow*)viewWindow)->getView(); + dispMode = aView->GetDisplayMode(); + } + else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); + AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode(); + dispMode = (mode == AIS_WireFrame ? 0 : 1 ); } - Sel->ClearIObjects(); + return dispMode; } - //===================================================================================== -// function : PrepareSubShapeSelection() -// purpose : (localContextId of the method is opened and defined here) +// function : DisplayGUI::InvertDisplayMode() +// purpose : Invert display mode ( shadin <-> wireframe ) for the viewer +// (current viewer if = 0 ) //===================================================================================== -bool DisplayGUI::PrepareSubShapeSelection(const int SubShapeType, Standard_Integer& returnLocalContextId) +void DisplayGUI::InvertDisplayMode( SUIT_ViewWindow* viewWindow ) { - //* Test the type of viewer */ - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return false; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - /* local context opening */ - //myGeomBase->SetDisplayedObjectList(); - this->OnDisplayOnly(); - - returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False); - SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection()); - SALOME_ListIteratorOfListIO It(Sel->StoredIObjects()); - for(;It.More();It.Next()) { - Handle(SALOME_InteractiveObject) IObject = It.Value(); - Standard_Boolean found; - Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found); - if(found && SubShapeType >= Shape->Shape().ShapeType()) { - ic->Load(Shape, (8 - SubShapeType), Standard_True); - ic->HilightWithColor(Shape, Quantity_NOC_RED); - } - } - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_SUBSHAPES")); - return true; + SetDisplayMode( 1 - GetDisplayMode( viewWindow ) ); } - //===================================================================================== -// function : PrepareSubShapeSelectionArgumentShape() -// purpose : ( localContextId of the method is opened and defined here ) +// function : DisplayGUI::ChangeDisplayMode() +// purpose : Set display mode for selected objects in the viewer given +// (current viewer if = 0 ) //===================================================================================== -bool DisplayGUI::PrepareSubShapeSelectionArgumentShape(const TopoDS_Shape& aShape,const int SubShapeType, Standard_Integer& returnLocalContextId) +void DisplayGUI::ChangeDisplayMode( const int mode, SUIT_ViewWindow* viewWindow ) { - //* Test the type of viewer */ - if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) - return false; - - if(aShape.IsNull()) - return false ; - - OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer(); - Handle (AIS_InteractiveContext) ic = v3d->getAISContext(); - - /* local context opening */ - //myGeomBase->SetDisplayedObjectList(); - this->OnDisplayOnly(); - - returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ; - - Handle(GEOM_AISShape) Shape = new GEOM_AISShape(aShape, ""); - ic->Display(Shape, 0, (8 - SubShapeType)); - - // Not Load(...) but Display(...) - // ic->Load(Shape, (8 - SubShapeType), Standard_True); - ic->HilightWithColor(Shape, Quantity_NOC_RED); - - QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_SUBSHAPES")); - return true; -} + SalomeApp_Application* app = getGeometryGUI()->getApp(); + if ( !app ) return; + + if ( !viewWindow ) + viewWindow = app->desktop()->activeWindow(); + + LightApp_SelectionMgr* aSelMgr = app->selectionMgr(); + if ( !aSelMgr ) return; + + SUIT_OverrideCursor(); + + SALOME_ListIO aList; + + if ( viewWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) { + SVTK_ViewWindow* vw = dynamic_cast( viewWindow ); + SVTK_View* aView = vw->getView(); + + aSelMgr->selectedObjects( aList ); + SALOME_ListIteratorOfListIO It( aList ); + for( ;It.More(); It.Next() ) { + SVTK_Viewer* stvkViewer = dynamic_cast(vw->getViewManager()->getViewModel()); + SVTK_Prs* vtkPrs = + stvkViewer ? dynamic_cast( stvkViewer->CreatePrs( It.Value()->getEntry() ) ) : 0; + if ( vtkPrs && !vtkPrs->IsNull() ) { + if ( mode == 0 ) + aView->ChangeRepresentationToWireframe( vtkPrs->GetObjects() ); + else if ( mode == 1 ) + aView->ChangeRepresentationToSurface( vtkPrs->GetObjects() ); + } + } + aView->Repaint(); + } + else if ( viewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) { + OCCViewer_Viewer* v3d = ((OCCViewer_ViewManager*)(viewWindow->getViewManager()))->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = v3d->getAISContext(); + + aSelMgr->selectedObjects( aList ); + SALOME_ListIteratorOfListIO It( aList ); + + for( ;It.More(); It.Next() ) { + SOCC_Viewer* soccViewer = (SOCC_Viewer*)(viewWindow->getViewManager()->getViewModel()); + SOCC_Prs* occPrs = dynamic_cast( soccViewer->CreatePrs( It.Value()->getEntry() ) ); + if ( occPrs && !occPrs->IsNull() ) { + AIS_ListOfInteractive shapes; occPrs->GetObjects( shapes ); + AIS_ListIteratorOfListOfInteractive interIter( shapes ); + for ( ; interIter.More(); interIter.Next() ) { + if ( mode == 0 ) + ic->SetDisplayMode( interIter.Value(), AIS_WireFrame, false ); + else if ( mode == 1 ) + ic->SetDisplayMode( interIter.Value(), AIS_Shaded, false ); + } + } + } + ic->UpdateCurrentViewer(); + } +} //===================================================================================== // EXPORTED METHODS //===================================================================================== extern "C" { - bool OnGUIEvent(int theCommandID, QAD_Desktop* parent) - {return DisplayGUI::OnGUIEvent(theCommandID, parent);} - - void BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO) - {return DisplayGUI::BuildPresentation(theIO);} +#ifdef WIN32 + __declspec( dllexport ) +#endif + GEOMGUI* GetLibGUI( GeometryGUI* parent ) + { + return new DisplayGUI( parent ); + } }