1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : DisplayGUI.cxx
25 // Author : Damien COQUERET
29 #include "DisplayGUI.h"
31 #include "QAD_RightFrame.h"
32 #include "GEOM_AssemblyBuilder.h"
33 #include "VTKViewer_ViewFrame.h"
34 #include "OCCViewer_ViewFrame.h"
35 #include "OCCViewer_Viewer3d.h"
36 #include "SALOMEGUI_ImportOperation.h"
37 #include "SALOME_ListIteratorOfListIO.hxx"
39 #include <AIS_ListIteratorOfListOfInteractive.hxx>
41 #include "utilities.h"
45 //=======================================================================
46 // function : DisplayGUI()
47 // purpose : Constructor
48 //=======================================================================
49 DisplayGUI::DisplayGUI() :
52 myGeomBase = new GEOMBase();
53 myGeomGUI = GEOMContext::GetGeomGUI();
54 myGeom = myGeomGUI->myComponentGeom;
58 //=======================================================================
59 // function : ~DisplayGUI()
60 // purpose : Destructor
61 //=======================================================================
62 DisplayGUI::~DisplayGUI()
67 //=======================================================================
68 // function : OnGUIEvent()
70 //=======================================================================
71 bool DisplayGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
73 DisplayGUI* myDisplayGUI = new DisplayGUI();
77 case 211: // MENU VIEW - WIREFRAME/SHADING
79 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
80 QApplication::setOverrideCursor(waitCursor);
82 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
84 int themode = myRenderInter->GetDisplayMode();
86 myRenderInter->SetDisplayMode(1);
87 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME"));
90 myRenderInter->SetDisplayMode(0);
91 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING"));
94 QApplication::restoreOverrideCursor();
96 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
97 QApplication::setOverrideCursor(Qt::waitCursor);
99 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
100 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
101 AIS_DisplayMode mode = (AIS_DisplayMode)ic->DisplayMode();
102 AIS_DisplayMode newmode = (mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame);
104 AIS_ListOfInteractive List;
105 ic->DisplayedObjects(List);
106 AIS_ListOfInteractive List1;
107 ic->ObjectsInCollector(List1);
110 AIS_ListIteratorOfListOfInteractive ite(List);
112 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
113 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
114 ic->SetDisplayMode(aSh,Standard_Integer(newmode),true);
119 ic->SetDisplayMode(newmode, Standard_False);
121 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_WIREFRAME"));
123 QAD_Application::getDesktop()->menuBar()->changeItem(211, tr("GEOM_MEN_SHADING"));
125 QApplication::restoreOverrideCursor();
129 case 212: // MENU VIEW - DISPLAY ALL
131 myDisplayGUI->OnDisplayAll();
134 case 213: // MENU VIEW - DISPLAY ONLY
136 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
137 myDisplayGUI->OnVTKDisplayOnly();
138 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC)
139 myDisplayGUI->OnDisplayOnly();
142 case 214: // MENU VIEW - ERASE ALL
144 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
145 ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->EraseAll();
146 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
147 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
148 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
150 ic->EraseAll(Standard_True, Standard_False);
151 ic->Display(v3d->getTrihedron());
155 case 215: // MENU VIEW - ERASE ONLY
157 myDisplayGUI->OnErase();
160 case 8031: // POPUP VIEWER - WIREFRAME/SHADING
162 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
164 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
166 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
167 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
169 QApplication::setOverrideCursor(Qt::waitCursor);
170 for(;It.More();It.Next()) {
171 Handle(SALOME_InteractiveObject) IOS = It.Value();
172 myRenderInter->SwitchRepresentation(IOS, false);
174 myRenderInter->Render();
175 QApplication::restoreOverrideCursor();
177 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
178 QApplication::setOverrideCursor(Qt::waitCursor);
179 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
180 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
181 Handle(AIS_InteractiveContext) ic = v3d->getAISContext();
182 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
183 for(;It.More();It.Next()) {
184 Handle(SALOME_InteractiveObject) IObject = It.Value();
185 Standard_Boolean found;
186 Handle(GEOM_AISShape) Shape = myDisplayGUI->myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
187 if(!Shape.IsNull()) {
188 AIS_DisplayMode mode = (AIS_DisplayMode)Shape->DisplayMode();
190 mode = (AIS_DisplayMode)ic->DisplayMode();
192 ic->SetDisplayMode(Shape, mode == AIS_WireFrame ? AIS_Shaded : AIS_WireFrame, false);
195 ic->UpdateCurrentViewer();
197 QApplication::restoreOverrideCursor();
202 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
210 //=================================================================================
211 // function : BuildPresentation()
213 //=================================================================================
214 void DisplayGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
216 DisplayGUI* myDisplayGUI = new DisplayGUI();
218 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
219 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
221 OCCViewer_Viewer3d* v3d;
222 Handle(AIS_InteractiveContext) ic;
223 vtkRenderer* Renderer;
225 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
226 v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
227 ic = v3d->getAISContext();
229 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
230 Renderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
236 MESSAGE("BuildPresentation(): null SALOME_InteractiveObject passed")
238 Standard_Boolean testResult;
239 GEOM::GEOM_Shape_var myGeomShape = myDisplayGUI->myGeomBase->ConvertIOinGEOMShape(theIO, testResult);
243 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
246 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
248 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry());
250 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
252 SALOMEDS::GenericAttribute_var anAttr;
253 SALOMEDS::AttributeName_var aName;
254 SALOMEDS::AttributeIOR_var anIOR;
256 if(myRenderInter->isInViewer(theIO)) {
257 myRenderInter->Display(theIO, false);
261 if(!obj->_is_nil()) {
262 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
263 // this SObject may be GEOM module root SObject
265 bool useSubItems = false;
266 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
267 if(myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
268 while (anIter->More() && !useSubItems) {
269 SALOMEDS::SObject_var subobj = anIter->Value();
270 SALOMEDS::GenericAttribute_var aTmpAttr;
271 if (subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
272 if (!myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
285 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
286 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
287 GEOM::GEOM_Shape_var aShape = myDisplayGUI->myGeom->GetIORFromString(anIOR->Value());
288 TopoDS_Shape Shape = myDisplayGUI->myGeomGUI->GetShapeReader().GetShape(myDisplayGUI->myGeom,aShape);
290 if(obj->FindAttribute(anAttr, "AttributeName")) {
291 aName = SALOMEDS::AttributeName::_narrow(anAttr);
293 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
294 vtkActorCollection* theAllActors = theRenderer->GetActors();
295 theAllActors->InitTraversal();
296 vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
297 Handle(SALOME_InteractiveObject) anIObj;
298 // don't create new study object if it already exists
299 bool isDisplayed = false;
300 while(!(actor==NULL)) {
301 SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
303 if(Gactor->hasIO()) {
304 if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
306 anIObj = Gactor->getIO();
307 if(!anIObj.IsNull()) myRenderInter->Display(anIObj, false);
311 actor=(vtkActor*)(theAllActors->GetNextActor());
315 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
318 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
319 aStudyBuilder->Addreference(newObj1, obj);
320 // commit transaction
323 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
324 int themode = myRenderInter->GetDisplayMode();
326 vtkActorCollection* theActors =
327 GEOM_AssemblyBuilder::BuildActors(Shape,0,themode,Standard_True);
328 theActors->InitTraversal();
329 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
330 while(!(anActor==NULL)) {
331 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
332 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myDisplayGUI->myGeomGUI->GetFatherior(),"GEOM");
333 IO->setEntry(obj->GetID());
335 GActor->setName(theIO->getName());
337 theRenderer->AddActor(GActor);
339 anActor = (vtkActor*)theActors->GetNextActor();
343 // next item iteration
346 anAttr = SALOMEDS::GenericAttribute::_nil();
347 while(anIter->More() && anAttr->_is_nil()) {
348 SALOMEDS::SObject_var subobject = anIter->Value();
349 SALOMEDS::GenericAttribute_var aTmpAttribute;
350 if (subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
351 anAttr = aTmpAttribute;
359 anAttr = SALOMEDS::GenericAttribute::_nil();
364 // No viewer update should be done here!
365 //myRenderInter->Render();
366 //QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser( true );
368 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
369 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
370 SALOMEDS::GenericAttribute_var anAttr;
371 SALOMEDS::AttributeName_var aName;
372 SALOMEDS::AttributeIOR_var anIOR;
374 if(v3d->isInViewer(theIO, true)) {
375 Standard_Boolean found;
376 Handle(GEOM_AISShape) aSh = myDisplayGUI->myGeomBase->ConvertIOinGEOMAISShape(theIO, found, true);
378 ic->Display(aSh, false);
379 ic->AddOrRemoveCurrentObject(aSh, false);
384 SALOMEDS::SObject_var obj = aStudy->FindObjectID(theIO->getEntry());
385 if(!obj->_is_nil()) {
386 MESSAGE("BuildPresentation(): SObject not null")
387 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
388 MESSAGE("BuildPresentation(): SObject has IOR")
389 // this SObject may be GEOM module root SObject
391 bool useSubItems = false;
392 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
393 if(myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(anAttr)->Value())->_is_nil()) {
394 while(anIter->More() && !useSubItems) {
395 SALOMEDS::SObject_var subobj = anIter->Value();
396 SALOMEDS::GenericAttribute_var aTmpAttr;
397 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
398 if(!myDisplayGUI->myGeom->GetIORFromString(SALOMEDS::AttributeIOR::_narrow(aTmpAttr)->Value())->_is_nil()) {
411 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
412 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
413 GEOM::GEOM_Shape_var aShape = myDisplayGUI->myGeom->GetIORFromString(anIOR->Value());
414 TopoDS_Shape Shape = myDisplayGUI->myGeomGUI->GetShapeReader().GetShape(myDisplayGUI->myGeom,aShape);
416 MESSAGE("BuildPresentation(): TopoDS_Shape is null!")
417 if(obj->FindAttribute(anAttr, "AttributeName")) {
418 MESSAGE("BuildPresentation(): SObject has Name")
419 aName = SALOMEDS::AttributeName::_narrow(anAttr);
420 // searchin for already displayed objects with the same shape
421 AIS_ListOfInteractive aDisplayed;
422 ic->DisplayedObjects(aDisplayed);
423 AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
424 Handle(AIS_Shape) anAISShape;
425 for(;anIObjects.More();anIObjects.Next()) {
426 anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
427 if(!anAISShape.IsNull()) {
428 if(anAISShape->Shape().IsSame(Shape))
430 anAISShape.Nullify();
433 if(!anAISShape.IsNull()) {
434 if(!ic->IsDisplayed(anAISShape))
435 ic->Display(anAISShape, false);
440 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
442 if (fatherSF->_is_nil())
443 MESSAGE("BuildPresentation(): fatherSF is nil!")
444 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
445 aStudyBuilder->Addreference(newObj1, obj);
446 // commit transaction
449 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
450 aSh->SetShadingColor(myDisplayGUI->myGeomBase->myShadingColor);
451 aSh->SetInfiniteState(Shape.Infinite());
452 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myDisplayGUI->myGeomGUI->GetFatherior(), "GEOM");
453 IO->setEntry(obj->GetID());
455 aSh->setName(aName->Value());
456 ic->Display(aSh, false);
458 ic->AddOrRemoveCurrentObject(aSh, false);
461 // next item iteration
464 anAttr=SALOMEDS::GenericAttribute::_nil();
465 while (anIter->More() && anAttr->_is_nil()) {
466 SALOMEDS::SObject_var subobject = anIter->Value();
467 SALOMEDS::GenericAttribute_var aTmpAttribute;
468 if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
469 anAttr = aTmpAttribute;
477 anAttr = SALOMEDS::GenericAttribute::_nil();
482 // No viewer update should be done here!
483 //QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser( true );
484 //ic->UpdateCurrentViewer();
489 //=====================================================================================
490 // function : OnDisplayAll()
492 //=====================================================================================
493 void DisplayGUI::OnDisplayAll(bool onlyPreviousDisplayedObject)
495 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
496 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
497 Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
499 //myContext->Display(v3d->getTrihedron());
501 if(!onlyPreviousDisplayedObject) {
502 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
503 SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
504 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SC);
505 for(; it->More();it->Next()) {
506 SALOMEDS::SObject_var CSO = it->Value();
507 SALOMEDS::AttributeIOR_var anIOR;
508 SALOMEDS::GenericAttribute_var anAttr;
509 if(CSO->FindAttribute(anAttr, "AttributeIOR")) {
510 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
511 Standard_Boolean testResult;
512 Handle(GEOM_AISShape) aSh = myGeomBase->ConvertIORinGEOMAISShape(anIOR->Value(), testResult);
514 myContext->Display(aSh);
516 GEOM::GEOM_Shape_ptr aShape = myGeom->GetIORFromString(anIOR->Value());
517 bool AddInSt = myGeomBase->mySettings_AddInStudy;
518 myGeomBase->mySettings_AddInStudy = false;
519 myGeomBase->Display(aShape);
520 myGeomBase->mySettings_AddInStudy = AddInSt;
526 AIS_ListOfInteractive aListDisplayedObject;
527 myContext->DisplayedObjects(aListDisplayedObject);
528 AIS_ListIteratorOfListOfInteractive ite(aListDisplayedObject);
530 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
531 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
533 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
534 if (v3d->isInViewer(GIO,true))
535 myContext->Display(aSh);
542 else if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
543 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
544 SALOMEDS::SComponent_var SC = aStudy->FindComponent("GEOM");
545 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SC);
546 for(; it->More();it->Next()) {
547 SALOMEDS::SObject_var CSO = it->Value();
548 SALOMEDS::AttributeIOR_var anIOR;
549 SALOMEDS::GenericAttribute_var anAttr;
550 if(CSO->FindAttribute(anAttr, "AttributeIOR")) {
551 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
552 Standard_Boolean testResult;
553 GEOM_Actor* aSh = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), testResult);
555 Handle(SALOME_InteractiveObject) IObject = aSh->getIO();
556 ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor()->Display(IObject);
559 GEOM::GEOM_Shape_ptr aShape = myGeom->GetIORFromString(anIOR->Value());
560 bool AddInSt = myGeomBase->mySettings_AddInStudy;
561 myGeomBase->mySettings_AddInStudy = false;
562 myGeomBase->Display(aShape);
563 myGeomBase->mySettings_AddInStudy = AddInSt;
572 //=====================================================================================
573 // function : OnVTKDisplayOnly()
575 //=====================================================================================
576 void DisplayGUI::OnVTKDisplayOnly()
578 QApplication::setOverrideCursor(Qt::waitCursor);
580 // Erase all not selected actors
581 vtkRenderer* aren = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
582 vtkActorCollection* theActors = aren->GetActors();
583 theActors->InitTraversal();
584 vtkActor *ac = theActors->GetNextActor();
586 if(ac->IsA("SALOME_Actor")) {
587 SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(ac);
588 if(!anActor->isHighlighted())
589 anActor->VisibilityOff();
591 ac = theActors->GetNextActor();
595 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
596 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
597 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
598 SALOMEDS::GenericAttribute_var anAttr;
599 SALOMEDS::AttributeName_var aName;
600 SALOMEDS::AttributeIOR_var anIOR;
602 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
603 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
605 for(;It.More();It.Next()) {
606 Handle(SALOME_InteractiveObject) IObject = It.Value();
607 SALOMEDS::SObject_var obj = aStudy->FindObjectID( IObject->getEntry() );
609 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
611 if(myRenderInter->isInViewer(IObject)) {
612 myRenderInter->Display(IObject);
616 if(!obj->_is_nil()) {
617 if(!obj->FindAttribute(anAttr, "AttributeIOR"))
619 // If selected object contains displayable subobjects, then do nothing
620 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
621 SALOMEDS::GenericAttribute_var aTmpAttr;
623 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
624 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
625 if(CORBA::is_nil(aShape)) continue;
626 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
628 if(obj->FindAttribute(anAttr, "AttributeName")) {
629 aName = SALOMEDS::AttributeName::_narrow(anAttr);
631 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
634 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
635 aStudyBuilder->Addreference(newObj1, obj);
636 // commit transaction
639 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
640 int themode = myRenderInter->GetDisplayMode();
641 vtkActorCollection* theActors = GEOM_AssemblyBuilder::BuildActors(Shape, 0, themode, Standard_True);
642 theActors->InitTraversal();
643 vtkActor* anActor = (vtkActor*)theActors->GetNextActor();
644 while(!(anActor==NULL)) {
645 GEOM_Actor* GActor = GEOM_Actor::SafeDownCast(anActor);
646 GActor->setIO(IObject);
647 GActor->setName(IObject->getName());
649 theRenderer->AddActor(GActor);
650 vtkRenderWindow *renWin = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->GetRenderWindow();
652 anActor = (vtkActor*)theActors->GetNextActor();
658 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser(true);
660 QApplication::restoreOverrideCursor();
665 //=====================================================================================
666 // function : OnDisplayOnly()
668 //=====================================================================================
669 void DisplayGUI::OnDisplayOnly()
671 if (QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
674 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
675 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
676 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
678 AIS_ListOfInteractive List;
679 ic->DisplayedObjects(List);
680 AIS_ListIteratorOfListOfInteractive ite(List);
682 if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
683 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
684 if (!ic->IsSelected( aSh )) {
685 ic->Erase(aSh, Standard_True, Standard_True);
691 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
692 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
694 SALOME_ListIteratorOfListIO It1(Sel->StoredIObjects());
695 for(;It1.More();It1.Next()) {
696 Handle(SALOME_InteractiveObject) IObject = It1.Value();
698 SALOMEDS::SObject_var fatherSF =
699 aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
700 if(v3d->isInViewer(IObject, true)) {
701 AIS_ListOfInteractive List1;
702 ic->ObjectsInCollector(List1);
703 AIS_ListIteratorOfListOfInteractive ite1(List1);
705 if(ite1.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
706 Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite1.Value());
708 Handle(GEOM_InteractiveObject) GIO = Handle(GEOM_InteractiveObject)::DownCast(aSh->getIO());
709 if (IObject->isSame(GIO)) {
711 ic->AddOrRemoveCurrentObject(aSh, true);
720 if (IObject->hasEntry()) {
721 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
722 SALOMEDS::GenericAttribute_var anAttr;
723 SALOMEDS::AttributeName_var aName;
724 SALOMEDS::AttributeIOR_var anIOR;
725 if (!obj->_is_nil()) {
726 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
727 // this SObject may be GEOM module root SObject
729 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
730 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
731 if(CORBA::is_nil(aShape)) continue;
732 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
734 if(obj->FindAttribute(anAttr, "AttributeName")) {
735 aName = SALOMEDS::AttributeName::_narrow(anAttr);
737 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
740 SALOMEDS::SObject_var newObj1 = aStudyBuilder->NewObject(fatherSF);
741 aStudyBuilder->Addreference(newObj1, obj);
742 // commit transaction
746 Handle(GEOM_AISShape) aSh = new GEOM_AISShape(Shape, aName->Value());
747 Handle(GEOM_InteractiveObject) IO = new GEOM_InteractiveObject(anIOR->Value(), myGeomGUI->GetFatherior(),"GEOM");
749 IO->setEntry(obj->GetID());
751 aSh->setName(aName->Value());
753 ic->AddOrRemoveCurrentObject(aSh, true);
762 //=====================================================================================
763 // function : OnErase()
765 //=====================================================================================
766 void DisplayGUI::OnErase()
768 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
769 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
770 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
772 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
773 Handle(SALOME_InteractiveObject) anIObject;
774 for(;It.More();It.Next()) {
775 anIObject = It.Value();
776 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
778 if(myRenderInter->isInViewer(anIObject)) {
779 myRenderInter->Erase(anIObject);
782 SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
783 SALOMEDS::GenericAttribute_var anAttr;
784 SALOMEDS::AttributeIOR_var anIOR;
785 if(!obj->_is_nil()) {
786 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
787 // this SObject may be GEOM module root SObject
788 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
789 bool useSubItems = false;
790 while(anIter->More() && !useSubItems) {
791 SALOMEDS::SObject_var subobj = anIter->Value();
792 SALOMEDS::GenericAttribute_var aTmpAttr;
793 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
802 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
803 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
804 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
805 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
806 if(obj->FindAttribute(anAttr, "AttributeName")) {
807 // searchin for already displayed objects with the same shape
808 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
809 vtkActorCollection* theAllActors = theRenderer->GetActors();
810 theAllActors->InitTraversal();
811 vtkActor* actor = (vtkActor*)theAllActors->GetNextActor();
812 Handle(SALOME_InteractiveObject) anIObj;
813 // don't create new study object if it already exists
814 bool isDisplayed = false;
815 while(!(actor==NULL)) {
816 SALOME_Actor* Gactor = SALOME_Actor::SafeDownCast(actor);
818 if(Gactor->hasIO()) {
819 if(strcmp(Gactor->getIO()->getEntry(),obj->GetID())==0) {
821 anIObj = Gactor->getIO();
823 myRenderInter->Erase(anIObj);
827 actor=(vtkActor*)(theAllActors->GetNextActor());
832 anAttr=SALOMEDS::GenericAttribute::_nil();
833 while(anIter->More() && anAttr->_is_nil()) {
834 SALOMEDS::SObject_var subobject = anIter->Value();
835 SALOMEDS::GenericAttribute_var aTmpAttribute;
836 if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
837 anAttr = aTmpAttribute;
845 anAttr = SALOMEDS::GenericAttribute::_nil();
852 else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
854 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
855 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
856 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
857 Handle(SALOME_InteractiveObject) anIObject;
858 for(;It.More();It.Next()) {
859 anIObject = It.Value();
860 if(v3d->isInViewer(anIObject, true)) {
861 Standard_Boolean found;
862 Handle(GEOM_AISShape) aSh = myGeomBase->ConvertIOinGEOMAISShape(anIObject, found, true);
865 ic->AddOrRemoveCurrentObject(aSh, true);
869 SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
870 SALOMEDS::GenericAttribute_var anAttr;
871 SALOMEDS::AttributeIOR_var anIOR;
872 if(!obj->_is_nil()) {
873 if(obj->FindAttribute(anAttr, "AttributeIOR")) {
874 // this SObject may be GEOM module root SObject
875 SALOMEDS::ChildIterator_var anIter = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument()->NewChildIterator(obj);
876 bool useSubItems = false;
877 while(anIter->More() && !useSubItems) {
878 SALOMEDS::SObject_var subobj = anIter->Value();
879 SALOMEDS::GenericAttribute_var aTmpAttr;
880 if(subobj->FindAttribute(aTmpAttr, "AttributeIOR")) {
889 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
890 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
891 GEOM::GEOM_Shape_var aShape = myGeom->GetIORFromString(anIOR->Value());
892 TopoDS_Shape Shape = myGeomGUI->GetShapeReader().GetShape(myGeom, aShape);
893 if(obj->FindAttribute(anAttr, "AttributeName")) {
894 // searchin for already displayed objects with the same shape
895 AIS_ListOfInteractive aDisplayed;
896 ic->DisplayedObjects(aDisplayed);
897 AIS_ListIteratorOfListOfInteractive anIObjects(aDisplayed);
898 Handle(AIS_Shape) anAISShape;
899 for(;anIObjects.More();anIObjects.Next()) {
900 anAISShape = Handle(AIS_Shape)::DownCast(anIObjects.Value());
901 if(!anAISShape.IsNull()) {
902 if(anAISShape->Shape().IsSame(Shape))
904 anAISShape.Nullify();
907 if(!anAISShape.IsNull()) {
908 if(ic->IsDisplayed(anAISShape))
909 ic->Erase(anAISShape);
914 anAttr=SALOMEDS::GenericAttribute::_nil();
915 while(anIter->More() && anAttr->_is_nil()) {
916 SALOMEDS::SObject_var subobject = anIter->Value();
917 SALOMEDS::GenericAttribute_var aTmpAttribute;
918 if(subobject->FindAttribute(aTmpAttribute, "AttributeIOR")) {
919 anAttr = aTmpAttribute;
927 anAttr = SALOMEDS::GenericAttribute::_nil();
934 Sel->ClearIObjects();
938 //=====================================================================================
939 // function : PrepareSubShapeSelection()
940 // purpose : (localContextId of the method is opened and defined here)
941 //=====================================================================================
942 bool DisplayGUI::PrepareSubShapeSelection(const int SubShapeType, Standard_Integer& returnLocalContextId)
944 //* Test the type of viewer */
945 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
948 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
949 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
951 /* local context opening */
952 //myGeomBase->SetDisplayedObjectList();
953 this->OnDisplayOnly();
955 returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False);
956 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
957 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
958 for(;It.More();It.Next()) {
959 Handle(SALOME_InteractiveObject) IObject = It.Value();
960 Standard_Boolean found;
961 Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found);
962 if(found && SubShapeType >= Shape->Shape().ShapeType()) {
963 ic->Load(Shape, (8 - SubShapeType), Standard_True);
964 ic->HilightWithColor(Shape, Quantity_NOC_RED);
967 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_SUBSHAPES"));
972 //=====================================================================================
973 // function : PrepareSubShapeSelectionArgumentShape()
974 // purpose : ( localContextId of the method is opened and defined here )
975 //=====================================================================================
976 bool DisplayGUI::PrepareSubShapeSelectionArgumentShape(const TopoDS_Shape& aShape,const int SubShapeType, Standard_Integer& returnLocalContextId)
978 //* Test the type of viewer */
979 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
985 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
986 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
988 /* local context opening */
989 //myGeomBase->SetDisplayedObjectList();
990 this->OnDisplayOnly();
992 returnLocalContextId = ic->OpenLocalContext(Standard_False, Standard_True, Standard_False, Standard_False) ;
994 Handle(GEOM_AISShape) Shape = new GEOM_AISShape(aShape, "");
995 ic->Display(Shape, 0, (8 - SubShapeType));
997 // Not Load(...) but Display(...)
998 // ic->Load(Shape, (8 - SubShapeType), Standard_True);
999 ic->HilightWithColor(Shape, Quantity_NOC_RED);
1001 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_SELECT_SUBSHAPES"));
1006 //=====================================================================================
1008 //=====================================================================================
1011 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1012 {return DisplayGUI::OnGUIEvent(theCommandID, parent);}
1014 void BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
1015 {return DisplayGUI::BuildPresentation(theIO);}